0

I am using imagerotate() and imagecreatefromstring() function to rotate the base64 image and update back to MySQL.
This is my code

    $imageData = $rs[0]['image_data'];//image from DB

    $im = imagecreatefromstring($imageData);

    $degrees = $_REQUEST['selectrotate'];//Dynamic degrees.


    ob_start();
    $destImage = imagerotate($im, $degrees, 0) ;     
    imageJPEG($destImage);

    $image_thumb =mysql_real_escape_string(ob_get_contents());
    $imageDV=$image_thumb;
    ob_end_clean(); 

Here what is happening:

$destImage = imagerotate($im, $degrees, 0); 

In this line when I hard code $degrees replacing some values, rotation is working fine. But for dynamic degrees, rotation is taking +180. If dynamic value is 90 then image is rotated to 270 degrees.

Please help.

Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52
  • 1
    Sounds like its getting set as negative. (270° = -90°) Is your form passing in the right value under the hood? – Anthony Sep 16 '14 at 06:51
  • Yes Anthony. I am getting correct values for $_REQUEST['selectrotate']; – user3918082 Sep 16 '14 at 06:52
  • 3
    Also, donno if you read the PHP manual, but it rotates the image, ANTI-clockwise, so if you selected 90 degrees, and it rotates 270° degrees in the opposite direction, it's just 90° degrees anti clockwise. See the manual: http://php.net/manual/en/function.imagerotate.php As @Anthony stated, 270° = -90°, which in turn is still 90° (But in opposite direction), so it's rotating correctly. – Zander Rootman Sep 16 '14 at 06:53
  • That's interesting, but why would it have different output for request variable versus hard coded? – Anthony Sep 16 '14 at 06:57
  • Did you only hard code test with 180° ? – Zander Rootman Sep 16 '14 at 06:58
  • Zander Rootman i did tested it with all values.. its coming correct. – user3918082 Sep 16 '14 at 07:00
  • And my image data is coming from DB which is in base 64 format – user3918082 Sep 16 '14 at 07:01

0 Answers0