note 37329 added to function.imagerotate
| From: | paul at mapson dot varent dot net | Date: | Tue, 11 Nov 2003 02:57:24 +0000 |
| Subject: | note 37329 added to function.imagerotate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60223@lists.php.net to get a copy of this message | ||
Ok, after using all of the examples listed in the comments here, I could not get ANY of them to work
in PHP 4.3.1
So, I give you this:
<?PHP
$filename = "image.jpg";
$degrees = "90";
$imagesize = getimagesize($filename);
$x = $imagesize[0];
$y = $imagesize[1];
if($x >= $y)
{
if($degrees == "-90")
{
$src_img = ImageCreateFromJPEG($filename);
$rotated = ImageRotate($src_img,"-90",0);
ImageJPEG($rotated, $filename, 85);
}
else
{
$src_img = ImageCreateFromJPEG($filename);
$preRotate = ImageRotate($src_img,"-90",0);
$rotated = ImageRotate($preRotate,"-180",0);
ImageJPEG($rotated, $filename, 85);
}
}
else
{
if($degrees == "-90")
{
$src_img = ImageCreateFromJPEG($filename);
$a = $y / 2;
$b = $x / 2;
$pos = $a - $b;
$placeholder = imagecreatetruecolor($y, $y);
imagecopy($placeholder, $src_img, $pos, "0", "0", "0", $x, $y);
$rotated = imagerotate($placeholder, "-90", 0);
$newImage = imagecreatetruecolor($y, $x);
imagecopy($newImage, $rotated, 0, 0, 0, $pos, $y, $x);
imagejpeg($newImage, $filename, "90");
}
else
{
$src_img = ImageCreateFromJPEG($filename);
$a = $y / 2;
$b = $x / 2;
$pos = $a - $b;
$placeholder = imagecreatetruecolor($y, $y);
imagecopy($placeholder, $src_img, $pos, "0", "0", "0", $x, $y);
$rotated = imagerotate($placeholder, "90", 0);
$newImage = imagecreatetruecolor($y, $x);
imagecopy($newImage, $rotated, 0, 0, 0, $pos, $y, $x);
imagejpeg($newImage, $filename, "90");
}
}
?>
Thats worked on 4 different servers running BSD, Linux, Windows 2000, its not a kludge or haphazard
method, this should WORK. Remove "mapson" from my email addy if you want to get in touch
with me.
----
Manual Page -- http://www.php.net/manual/en/function.imagerotate.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37329
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37329&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37329&report=yes
Search -- http://master.php.net/manage/user-notes.php