I have a function to make thumbnail of a url image on fly! I always pass to this functions images with type jpg, but the problem appears when I pass an image with ".jpg" extension. but when i try to get its mime type, i found that's "application/octet-stream" .. in this php page, this mime type refers to one of
IMAGETYPE_JPC,IMAGETYPE_JPX,IMAGETYPE_JB2
what I need to modify my function to handle this mime type ??
notice ^^^^^^
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";
}
}
The application/octet-stream MIME type is used for unknown binary files. It preserves the file contents, but requires the receiver to determine file type, for example, from the filename extension. The Internet media type for an arbitrary byte stream is application/octet-stream .
You can't DECODE it to readable values without knowing which ENCODING was used. All you have is what TYPE the data is - not how it was ENCODED. You need to look at the Content-Encoding header (if there is one - if not, you need to ask the sender of the data how to decode it).
Follow these Steps: In Octet-stream you will be receiving the response as "Encoded Binary Data" Your need to convert the response data into "Decoded Base64 String" Finally save it as PDF.
We can't tell you because application/octet-stream
is a sort of general-type-of-binary-file mime-type. It can be everything. You can try with imagecreatefromstring
on the files binary content. But keep fingers crossed ;).
The actual issue here is that getimagesize
is independent to the GD library you use for resizing the image. So it provides infos about files GD itself is not able to deal with. So you can just output some sort of "unsupported image type" until you find some additional library that is able to deal with the specific mime- or better saying image-type.
See as well:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With