note 46338 added to function.imagerotate
| From: | jonatdriestonedotcom at osu1 dot php dot net | Date: | Thu, 07 Oct 2004 15:42:30 +0000 |
| Subject: | note 46338 added to function.imagerotate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78139@lists.php.net to get a copy of this message | ||
imagerotate does not preserve the alpha channel, so if you want to rotate a PNG you need to get
creative. I don't see any command to retrieve the alpha information from an image (as far as
I could see,) so you'll have to do a bit of manual labor before hand. In my case I created a
second PNG file with the alpha saved as RGB data and manually "copied" the data from
source
to destination:
function alpha_rotate($dst,$src,$rotate,$offsetX,$offsetY){
$top = imagecreatefrompng("image_processing/shadow.png");
$top_alpha = imagecreatefrompng("image_processing/shadow_alpha.png");
imagecopyresampled($top,$src,0,0,0,0,100,100,100,100);
$top = imagerotate($top,$rotate,0x000000);
$top_alpha = imagerotate($top_alpha,$rotate,0x000000);
for ($theX=0;$theX<imagesx($top);$theX++){
for ($theY=0;$theY<imagesy($top);$theY++){
$rgb = imagecolorat($top,$theX,$theY);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$rgb = imagecolorat($top_alpha,$theX,$theY);
$a = $rgb & 0xFF;
$a = 127-floor($a/2);
$myColor = imagecolorallocatealpha($top,$r,$g,$b,$a);
imagesetpixel($dst,($theX+$offsetX),($theY+$offsetY),$myColor);
}
}
}
----
Manual Page -- http://www.php.net/manual/en/function.imagerotate.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46338
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46338&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46338&report=yes
Search -- http://master.php.net/manage/user-notes.php