@deathshadow and others... I am working on a script that allows to rotate images before upload. All images load up fine except transparent gif images. They load fine if not rotated, but when rotated they do not show up in the upload folder. The $source echos empty. I am thinking the issue is somewhere here: ...... $allowTypes = array('image/png','image/jpg','image/jpeg','image/gif'); ...... if(!empty($rotation)){ switch($fileType){ case 'image/png': $source = imagecreatefrompng($fileTemp); break; case 'image/gif': $source = imagecreatefromgif($fileTemp); break; default: $source = imagecreatefromjpeg($fileTemp); } $imageRotate = imagerotate($source, $rotation,0); switch($fileType){ case 'image/png': $upload = imagepng($imageRotate, $filePath); break; case 'image/gif': $upload = imagegif($imageRotate, $filePath); break; default: $upload = imagejpeg($imageRotate, $filePath); } } Code (markup): Is there something I am missing?
Your code is working perfect for me. What is the rotation angle you are using? People have reported bugs here when using certain angles https://www.php.net/manual/en/function.imagerotate.php Can you provide the image you are using? Don't attach to a comment here. Upload on your server and post link to gif please. Can you run this code: //source file name $fileTemp='animal.gif'; //destination file name $filePath = 'animal11.gif'; $source = imagecreatefromgif($fileTemp); if( !$source ){ echo "no image"; }else{ echo "got image"; } $imageRotate = imagerotate($source, 180, 0); if( !$imageRotate ){ echo " no rotation"; }else{ echo " Done rotation"; } $upload = imagegif($imageRotate, $filePath);
This is the gif image I used to test it: https://www7.lunapic.com/editor/premade/transparent.gif It loads fine if it's not rotated. When I rotate and save it, nothing shows in the upload folder. Zero, zilch.
Try to use this method to read $source file: $source= imagecreatefromstring( file_get_contents( $fileTemp)); That "imagecreatefromgif" is not recognizing this as valid GIF image. The above method worked for me.
So out of everything I could have chosen I chose a wrong image... Hmm... I am going to test it with a different image to see if the issue isn't there.
This is working. Thank you. I tried gif animated images, still images and that image that didn't work, all of them got uploaded.