Jump to content

Rotate Images


owner

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/185667-rotate-images/
Share on other sites

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);

Link to comment
https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980404
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980411
Share on other sites

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!!! :)

Link to comment
https://forums.phpfreaks.com/topic/185667-rotate-images/#findComment-980413
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.