note 37329 deleted from function.imagerotate by aidan

From: Date: Mon, 04 Oct 2004 07:03:37 +0000
Subject: note 37329 deleted from function.imagerotate by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77883@lists.php.net to get a copy of this message
Note Submitter: paul at mapson dot varent dot net ---- 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.

« previous php.notes (#77883) next »