note 92794 added to function.imagerotate
| From: | sjef at bosman dot fr | Date: | Sun, 09 Aug 2009 16:28:31 +0000 |
| Subject: | note 92794 added to function.imagerotate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159240@lists.php.net to get a copy of this message | ||
I wanted to draw a transparent GIF-image and show it on a page, at an angle specified in the URL:
<img src="image.php?angle=90" type="image/gif">
I used the native imagerotate() but at angles of 90, 180, etc. the old background colour would
become non-transparent. Apparently, there's a bug somewhere in GD, and has been for ages.
My solution below:
$height = 100;
$width = 100;
$lsize= $width/2;
$angle= $_GET["angle"];
// avoid the bug:
if(($angle%90)==0)
$angle+= 0.001;
$image_p = imagecreatetruecolor($width, $height);
$trans = imagecolorallocate($image_p, 254, 0, 0);
imagefill($image_p, 0, 0, $trans);
imagecolortransparent($image_p, $trans);
$black = imagecolorallocate($image_p, 1, 1, 1);
$red = imagecolorallocate($image_p, 255, 0, 0);
$white = imagecolorallocate($image_p, 255, 255, 255);
// draw something here
imageline($image_p, 3, $lsize, $lsize/2, $lsize, $black);
$image_r= imagerotate($image_p, -$angle, $trans, 0);
$w= imagesx($image_r);
$h= imagesy($image_r);
$image_s = imagecreatetruecolor($width, $height);
imagecopyresized($image_s, $image_r, 0, 0, ($w-$width)/2, ($h-$height)/2, $width, $height, $width,
$height);
$trans = imagecolorallocate($image_s, 254, 0, 0);
imagecolortransparent($image_s, $trans);
imagegif($image_s);
----
Server IP: 208.69.120.35
Probable Submitter: 83.205.25.185
----
Manual Page -- http://www.php.net/manual/en/function.imagerotate.php
Edit -- https://master.php.net/note/edit/92794
Del: integrated -- https://master.php.net/note/delete/92794/integrated
Del: useless -- https://master.php.net/note/delete/92794/useless
Del: bad code -- https://master.php.net/note/delete/92794/bad+code
Del: spam -- https://master.php.net/note/delete/92794/spam
Del: non-english -- https://master.php.net/note/delete/92794/non-english
Del: in docs -- https://master.php.net/note/delete/92794/in+docs
Del: other reasons-- https://master.php.net/note/delete/92794
Reject -- https://master.php.net/note/reject/92794
Search -- https://master.php.net/manage/user-notes.php