note 43135 added to function.imagerotate

From: Date: Thu, 10 Jun 2004 15:48:21 +0000
Subject: note 43135 added to function.imagerotate
Groups: php.notes 
Request: Send a blank email to php-notes+get-70886@lists.php.net to get a copy of this message
To remove the black band on the side of the picture, I had to take into account the fact the the origin of the picture is moved. I use the following code (I only do 90, 180 or 270 degree rotation): //$thumbnail_height and $thumbnail_width are //the dimensions of the target picture. //$im is the source image //Make sure that the resized image will fit after rotation $thumbnail_max=2*($thumbnail_height>$thumbnail_width)? $thumbnail_height:$thumbnail_width; $small_im=ImageCreateTrueColor($thumbnail_max,$thumbnail_max); imagecopyresized($small_im,$im,0,0,0,0, $thumbnail_width,$thumbnail_height,imagesx($im),imagesy($im)); //Rotate the image $small_im=imagerotate($small_im,$rotation,0); //Now you need to compute the final origin of the of the image if ($rotation==270) { $final_orx=$thumbnail_width-$thumbnail_height; $final_ory=0; } else if ($rotation==180) { $final_orx=0; $final_ory=$thumbnail_width-$thumbnail_height; } else { $final_orx=0; $final_ory=0; } if (($rotation==90)||($rotation==270)) { $final_height=$thumbnail_width; $final_width=$thumbnail_height; } else { $final_height=$thumbnail_height; $final_width=$thumbnail_width; } $rotated_im=ImageCreateTrueColor($final_width,$final_height); ImageCopyResampled($rotated_im,$small_im,0,0,$final_orx,$final_ory, $final_width,$final_height,$final_width,$final_height); //The result is in $rotated_im ---- Manual Page -- http://www.php.net/manual/en/function.imagerotate.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43135 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43135&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43135&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#70886) next »