note 43135 deleted from function.imagerotate by aidan
| From: | aidan@php.net | Date: | Mon, 04 Oct 2004 07:06:08 +0000 |
| Subject: | note 43135 deleted from function.imagerotate by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77887@lists.php.net to get a copy of this message | ||
Note Submitter: Nicolas Delerue
----
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