Topic: Image is one size when written but almost 100x larger when opened?!
I'm not sure if this is really a PHP question, but it's causing PHP errors, so I thought I'd post in here requesting help.
I have a JPG that's ~1.5MB on disk. It's 300 dpi and roughly 5700 x 4900 pixels when opened in Photoshop. When I try creating a new image from it, I get a fatal error:
Fatal error: Allowed memory size of 94371840 bytes exhausted (tried to allocate 22800 bytes) in *** on line 204
My code is set to reject anything larger than 4 MB, so the aforementioned image "sneaks through" since, again, it's only 1.5 according to the file system.
Does anyone know what would cause PHP to see the file as ~90MB when trying to use imagecreatefromjpg? If there's a way to "reveal" this information to PHP before opening the file, I'd happily reject it, but I'm not sure how to do that...
I'd appreciate any advice or direction anyone can provide! Thanks in advance!!!
Edit: here's the offending line:
// Use relevant function based on $mime. if (stristr($mime, "png")) $imgB=imagecreatefrompng(T_DIR.$fname); else $imgB=imagecreatefromjpeg(T_DIR.$fname); // This is line "204" referenced in the error message above. imagecopyresampled($imgA, $imgB, 0, 0, 0, 0, $iWW, $iHH, $iW, $iH); imagepng($imgA, T_DIR.basename($fname)); imagedestroy($imgA); imagedestroy($imgB);