When images are uploaded to my site I convert all of them to jpgs using gd lib:
$image = imagecreatefrompng($img);
$outputFile = str_replace('png', 'jpg', $img);
unlink($img);
imagejpeg($image, $outputFile, $quality);
imagedestroy($image);
This works perfectly fine until I need to make a copy of an image for cropping. It fails in imagecreatefromjpeg()
Looking at the image details with getimagesize($outputFile)
I can see that even though I have successfully converted a png or gif to a jpg, and it has a jpg file extension the mime type is still image/png or image/gif.
For example:
Array
(
[0] => 250
[1] => 188
[2] => 3
[3] => width="250" height="188"
[bits] => 8
[mime] => image/png
)
How do I change the mime type when I convert to jpg then? Or what can I do to stop it failing when I need to do something to the image like copy it or resize it for cropping using imagecreatefromjpeg()
?