-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Some websites "lie" about the image type, maybe because a user uploads a PNG that then gets downscaled and converted to a JPEG, but keeps the .png extension and is reported as image/png anyway.
It'd be wonderful if there was an option to instead report the true image type from the file signature.
I've managed to kinda work around this with a (badly coded) userscript that, given an image as an arraybuffer, gets the true image type and replaces the MIME type in the header, however I wouldn't know how to integrate this into the extension code myself.
Partial userscript code
function getImageType(arrayBuffer) {
var type;
var dv = new DataView(arrayBuffer, 0, 5);
var nume1 = dv.getUint8(0, true);
var nume2 = dv.getUint8(1, true);
var hex = nume1.toString(16) + nume2.toString(16) ;
switch(hex) {
case "8950":
type = "image/png";
break;
case "4749":
type = "image/gif";
break;
case "424d":
type = "image/bmp";
break;
case "ffd8":
type = "image/jpeg";
break;
default:
type = null;
break;
}
return type;
}
// [...]
document.getElementById("imgData-mime").innerText = imgType;
// Then this extension looks at imgData-mime and reads what I've written there insteadevan-king
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request