Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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