note 91803 added to function.imagerotate
| From: | Anonymous at osu1 dot php dot net | Date: | Fri, 26 Jun 2009 00:32:19 +0000 |
| Subject: | note 91803 added to function.imagerotate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-157515@lists.php.net to get a copy of this message | ||
Sorry, the previous class contains an error, the original image after the rotation 1px move on and
get the unwanted "border".
After a careful reading of the local debate, I am using the tip from Dave Richards wrote a new
function. With its images can be rotated only 90 ° (default), 180 ° and 270 °, but one
rarely needs more ...
The function returns False, or rotated image
<?php
if(!function_exists("imagerotate")) {
function imagerotate($srcImg, $angle, $bgcolor, $ignore_transparent = 0) {
return rotateImage($srcImg, $angle);
}
}
function rotateImage($img1, $rec) {
$wid = imagesx($img1);
$hei = imagesy($img1);
switch($rec) {
case 270:
$img2 = @imagecreatetruecolor($hei, $wid);
break;
case 180:
$img2 = @imagecreatetruecolor($wid, $hei);
break;
default :
$img2 = @imagecreatetruecolor($hei, $wid);
}
if($img2) {
for($i = 0;$i < $wid; $i++) {
for($j = 0;$j < $hei; $j++) {
$ref = imagecolorat($img1,$i,$j);
switch($rec) {
case 270:
if(!@imagesetpixel($img2, ($hei - 1) - $j, $i, $ref)){
return false;
}
break;
case 180:
if(!@imagesetpixel($img2, $i, ($hei - 1) - $j, $ref)) {
return false;
}
break;
default:
if(!@imagesetpixel($img2, $j, ($wid - 1) - $i, $ref)) {
return false;
}
}
}
}
return $img2;
}
return false;
}
?>
Petr
----
Server IP: 64.71.164.2
Probable Submitter: 217.77.165.46
----
Manual Page -- http://www.php.net/manual/en/function.imagerotate.php
Edit -- https://master.php.net/note/edit/91803
Del: integrated -- https://master.php.net/note/delete/91803/integrated
Del: useless -- https://master.php.net/note/delete/91803/useless
Del: bad code -- https://master.php.net/note/delete/91803/bad+code
Del: spam -- https://master.php.net/note/delete/91803/spam
Del: non-english -- https://master.php.net/note/delete/91803/non-english
Del: in docs -- https://master.php.net/note/delete/91803/in+docs
Del: other reasons-- https://master.php.net/note/delete/91803
Reject -- https://master.php.net/note/reject/91803
Search -- https://master.php.net/manage/user-notes.php