I am trying to verify if a link is a valid image with magic number. Most of the images link work fine. But here are set of images on trump's site that does not produce correct magic numbers, though they appear to work fine on browser. Magic number they produce is 3c21444f.
Below is my code, Any help would be appreciated:
var request = require('request');
var magic = {
jpg: 'ffd8ffe0',
jpg1: 'ffd8ffe1',
png: '89504e47',
gif: '47494638'
};
var options = {
method: 'GET',
url: 'https://assets.donaldjtrump.com/gallery/4749/screen_shot_2016-10-30_at_1.39.54_pm.png',
encoding: null // keeps the body as buffer
};
request(options, function (error, response, body) {
if(!error) {
var magicNumberInBody = body.toString('hex', 0, 4);
if (magicNumberInBody == magic.jpg ||
magicNumberInBody == magic.jpg1 ||
magicNumberInBody == magic.png ||
magicNumberInBody == magic.gif) {
console.log('Valid image');
} else {
console.log('Invalid Image', magicNumberInBody);
}
}
});