owner Posted December 19, 2009 Share Posted December 19, 2009 Hello, I am trying to rotate my images using imagerotate (part of GD Library) but for some crazy reason, it doesn't seem to want to rotate gif or png images. I don't get any errors while trying to rotate the images as well. Here is the code I am using to try and rotate a png image. // Load $source = imagecreatefrompng('myimagetorotate.png'); // Rotate 90 Degrees $rotate = imagerotate($source, 90, 0); // Output imagepng($source,'myimagetorotate.png', 0, NULL); Like I said, I can rotate a jpg/jpeg image perfectly using this code (using imagecreatefromjpeg and imagejpeg respectfully) Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/185667-rotate-images/ Share on other sites More sharing options...
teamatomic Posted December 19, 2009 Share Posted December 19, 2009 I seem to remember from messing with this a while back that is you specify NULL you will also need to set a filter. Maybe something like: imagepng($source,'myimagetorotate.png', 0, PNG_NO_FILTER, NULL); HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980384 Share on other sites More sharing options...
owner Posted December 19, 2009 Author Share Posted December 19, 2009 Wrong parameter count for imagepng() in index.php Here is the syntax bool imagepng ( resource $image [, string $filename [, int $quality [, int $filters ]]] ) I tried PNG_FILTER_NONE PNG_NO_FILTER for the filter, but no luck Quote Link to comment https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980400 Share on other sites More sharing options...
The Little Guy Posted December 19, 2009 Share Posted December 19, 2009 I had this problem once, it was because the old image was still cached... do Ctrl+F5 to refresh and clear cache... Quote Link to comment https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980401 Share on other sites More sharing options...
owner Posted December 19, 2009 Author Share Posted December 19, 2009 Still not rotated lol Quote Link to comment https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980402 Share on other sites More sharing options...
The Little Guy Posted December 19, 2009 Share Posted December 19, 2009 The following should take the original and overwrite the original: $filename = 'somefile.gif'; $degree = 90; $source = imagecreatefromgif($filename); $rotate = imagerotate($source, $degree, 0); $colorTransparent = imagecolortransparent($source); imagefill($rotate, 0, 0, $colorTransparent); imagecolortransparent($source, $colorTransparent); imagegif($rotate, $filename); Quote Link to comment https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980404 Share on other sites More sharing options...
owner Posted December 19, 2009 Author Share Posted December 19, 2009 I am not very familiar with these three functions: imagecolortransparent($source); imagefill($rotate, 0, 0, $colorTransparent); imagecolortransparent($source, $colorTransparent); Will this preserve transparent backgrounds if present? Quote Link to comment https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980406 Share on other sites More sharing options...
The Little Guy Posted December 19, 2009 Share Posted December 19, 2009 I am not very familiar with these three functions: imagecolortransparent($source); imagefill($rotate, 0, 0, $colorTransparent); imagecolortransparent($source, $colorTransparent); Will this preserve transparent backgrounds if present? Yup! Quote Link to comment https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980408 Share on other sites More sharing options...
owner Posted December 19, 2009 Author Share Posted December 19, 2009 Would it be necessary to call the imagedestroy function? imagedestroy($rotate); Sorry for all the questions owner Quote Link to comment https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980410 Share on other sites More sharing options...
The Little Guy Posted December 19, 2009 Share Posted December 19, 2009 you can if you want... php should destroy it automatically once the script finishes. If you are doing it to more than one image at a time I would destroy the resource for each image when your done with it. I am not sure if you can destroy the $rotate or not I'm fairly sure you can't... Quote Link to comment https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980411 Share on other sites More sharing options...
owner Posted December 19, 2009 Author Share Posted December 19, 2009 Here is the final source code. Seems to work flawless $source = imagecreatefrompng('image.png'); $rotate = imagerotate($source, $rotationD, 0); $colorTransparent = imagecolortransparent($source); imagefill($rotate, 0, 0, $colorTransparent); imagecolortransparent($source, $colorTransparent); imagepng($rotate, 'image.png'); imagedestroy($rotate); Thank you very much!!! Quote Link to comment https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980413 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.