2

i have a problem with the imagerotate() PHP function. I run the script below, and it successfully creates the new image with imagejpeg(), but the new image is the same as the original, so it doesn't rotate it. It shows no error message in the Apache error.log, so i have no idea.

$file contains a filename in this form: IMG_8841.JPG

I hope you can help me, thanks.

$filename='./original/'.$file;
$new='./rotated/'.$file;
$original_photo = imagecreatefromjpeg($filename);
imagerotate ($original_photo , 90 , 0 );
imagejpeg($original_photo, $new);
imagedestroy($original_photo);
dpb
  • 82
  • 1
  • 9
  • If there were any errors it would shou on php, not on apache anyway, try to put error_reporting(E_ALL); at the beginning of the file to see if it drops any error – aleation Nov 20 '12 at 13:50
  • 1
    There are no errors, imagerotate simply does not change the given resource but returns a new (rotated) resource. – Jens Nov 20 '12 at 13:54

1 Answers1

6

Try

$original_photo = imagerotate($original_photo, 90, 0);

Else your object is not modified.

Or event better:

$new_photo = imagerotate ($original_photo , 90 , 0 );
imagejpeg($new_photo, $new); 
imagedestroy($original_photo);
imagedestroy($new_photo);
Jens
  • 2,050
  • 1
  • 14
  • 30
  • Oh, thanks. I was so dumb, i haven't read the imagerotate() manual. I thought it returns with an integer that indicates success. Thanks! – dpb Nov 20 '12 at 13:59
  • You're welcome. If the question is answered, you can "accept" the answer so that others can see it (and do not bother to look if they can help). – Jens Nov 20 '12 at 14:01