How to handle image mime type "application / octet-stream"?
I have a function to sketch a URL image on the fly! I always go to these image functions using the jpg type, but the problem occurs when I pass the image with the ".jpg" extension. but when i try to get its mime type i found that " application / octet-stream " .. in this php page this mime type refers to one of
IMAGETYPE_JPC, IMAGETYPE_JPX, IMAGETYPE_JB2
what do I need to change my function to handle this mime type?
notification ^^^^^^
function thumb($path,$width,$height) // $path => image url
{
$file_dimensions = getimagesize($path);
$file_type = image_type_to_mime_type($file_dimensions[2]);
list($Cwidth, $Cheight) = getimagesize($path);
if ($file_type=='image/jpeg'||$file_type=='image/pjpeg'){
// Load
$thumb = imagecreatetruecolor($width, $height);
$source = imagecreatefromjpeg($path);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $Cwidth, $Cheight);
header('Content-Type: image/jpeg');
imagejpeg($thumb);
}
else if ($file_type=='application/octet-stream')
{
// ^^^^^ what I should write here
}
else
{
echo "Not supported type";
}
}
source to share
We cannot tell you because is application/octet-stream
is a general-type-of-of-binary-file mime-type type. It could be anything. You can try with imagecreatefromstring
in binary content files. But keep your fingers crossed;).
The real problem here is that it getimagesize
doesn't depend on the GD library you are using to resize the image. Thus, it provides information about files that GD itself cannot handle. So you can just infer some "unsupported image type" until you find some additional library capable of handling a particular mime- or better say type.
See also:
source to share