Hi!
Here's a piece of code:
[begin]
<?php
Header('Content-type: image/png');
$sz = "";
$FileValue = 1000;
$i = strlen($FileValue);
for ( $j = 0; $j < 7-$i; $j++ )
{
$sz = $sz . "0";
}
$Img = imagecreate(56,13);
$Gold = imagecolorallocate($Img,148,128,100);
$Gray = imagecolorallocate($Img,32,32,32);
ImageFilledRectangle($Img,0,0,55,12,$Gray);
imagestring($Img,4,0,0,$sz.$FileValue,$Gold);
imagepng($Img);
ImageDestroy($Img);
?>
[end]
OK. Calling this script I have a png picture back.
Now I add imagecolortransparent($Img,$Gray); just before imagepng() and OK
again, I have a transparent picture back. But now, if I add:
$r = imagerotate($Img,90,0);
imagepng($r);
just after the imagecolortransparent() instruction seen above, I get a
rotated picture, but not transparent. How to solve that? I've used a plenty
of tricks, no one works.
Thanx. 6 16460
"AMcD" <ar*************@free.fr> writes: <?php Header('Content-type: image/png');
$sz = ""; $FileValue = 1000; $i = strlen($FileValue); for ( $j = 0; $j < 7-$i; $j++ ) { $sz = $sz . "0"; }
This isn't related to your problem, but are you familiar with the
sprintf() function? You're going to a lot of trouble to add leading
zeros when you could just do this:
$str = sprintf("%07d", $FileValue);
$Img = imagecreate(56,13); $Gold = imagecolorallocate($Img,148,128,100); $Gray = imagecolorallocate($Img,32,32,32); ImageFilledRectangle($Img,0,0,55,12,$Gray); imagestring($Img,4,0,0,$sz.$FileValue,$Gold); imagepng($Img); ImageDestroy($Img); ?>
OK. Calling this script I have a png picture back.
Now I add imagecolortransparent($Img,$Gray); just before imagepng() and OK again, I have a transparent picture back. But now, if I add:
$r = imagerotate($Img,90,0); imagepng($r);
just after the imagecolortransparent() instruction seen above, I get a rotated picture, but not transparent. How to solve that? I've used a plenty of tricks, no one works.
Create the first image with imagecreatetruecolor() and then create
the rotated image like this:
$r = imagerotate($Img, 90, $Gray);
imagecolortransparent($r, $Gray);
I just tested this and the rotated image had a transparent background.
--
Michael Fuhr http://www.fuhr.org/~mfuhr/
"AMcD" <ar*************@free.fr> wrote in message news:<3f***********************@news.free.fr>... Hi!
<snip>
I get a rotated picture, but not transparent. How to solve that? I've used a plenty of tricks, no one works.
The transparent support for PNG is broken in many browsers.
Search the net for more about the politics, workaround, and supporting
broswers, etc.
--
"If there is a God, he must be a sadist!"
Email: rrjanbiah-at-Y!com ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) writes: "AMcD" <ar*************@free.fr> wrote in message news:<3f***********************@news.free.fr>...
I get a rotated picture, but not transparent. How to solve that? I've used a plenty of tricks, no one works.
The transparent support for PNG is broken in many browsers. Search the net for more about the politics, workaround, and supporting broswers, etc.
The OP stated that the transparent background works for the original
image, so a broken browser doesn't appear to be the problem. In
another followup I posted a solution that worked for me.
--
Michael Fuhr http://www.fuhr.org/~mfuhr/
Michael Fuhr wrote: This isn't related to your problem, but are you familiar with the sprintf() function? You're going to a lot of trouble to add leading zeros when you could just do this:
$str = sprintf("%07d", $FileValue);
Err, it was just a quick sample ;o). But thanx for the comment (I'm just
starting with PHP).
Create the first image with imagecreatetruecolor() and then create the rotated image like this:
$r = imagerotate($Img, 90, $Gray); imagecolortransparent($r, $Gray);
I just tested this and the rotated image had a transparent background.
OK, then, you mean a stuff like that?
<?php
Header('Content-type: image/png');
$FileValue = 5000;
$sz = sprintf("%07d",$FileValue);
$Img = imagecreatetruecolor(56,13);
$Gold = imagecolorallocate($Img,148,128,100);
$Gray = imagecolorallocate($Img,32,32,32);
ImageFilledRectangle($Img,0,0,55,12,$Gray);
imagestring($Img,4,0,0,$sz.$FileValue,$Gold);
$r = imagerotate($Img,90,$Gray);
imagecolortransparent($r,$Gray);
imagepng($r);
ImageDestroy($Img);
ImageDestroy($r);
?>
I tried this stuff yet but... it fails too: no transparency. BTW my ISP uses
GD 1.8.x. Maybe it is related? At least, imagetruecolor isn't supported with
1.8.
Thanx for your help.
R. Rajesh Jeba Anbiah wrote: The transparent support for PNG is broken in many browsers. Search the net for more about the politics, workaround, and supporting broswers, etc.
Not this way dude. All browsers I'm using support transparency and when I
display the "horizontal" transparent PNG picture, there is no problem. I
suspect GD 1.8 instead...
Thanx for helping.
"AMcD" <ar*************@free.fr> writes: OK, then, you mean a stuff like that?
<?php Header('Content-type: image/png'); $FileValue = 5000; $sz = sprintf("%07d",$FileValue); $Img = imagecreatetruecolor(56,13); $Gold = imagecolorallocate($Img,148,128,100); $Gray = imagecolorallocate($Img,32,32,32); ImageFilledRectangle($Img,0,0,55,12,$Gray); imagestring($Img,4,0,0,$sz.$FileValue,$Gold);
Don't use $sz.$FileValue here -- sprintf() has already put the value
with leading zeros in $sz. You're displaying "00050005000", although
you probably don't see that because the image isn't big enough.
$r = imagerotate($Img,90,$Gray); imagecolortransparent($r,$Gray); imagepng($r); ImageDestroy($Img); ImageDestroy($r); ?>
I tried this stuff yet but... it fails too: no transparency. BTW my ISP uses GD 1.8.x. Maybe it is related? At least, imagetruecolor isn't supported with 1.8.
Sorry I didn't qualify my previous answer: I'm using GD 2.0.15.
Your example works with that version, so if it doesn't work with
1.8 then perhaps you could convince your ISP to upgrade. According
to phpinfo(), the GD library that comes bundled with recent versions
of PHP is "2.0.15 compatible" so upgrading is easy enough to do,
logistics and potential backward-compatibility problems aside.
--
Michael Fuhr http://www.fuhr.org/~mfuhr/ This discussion thread is closed Replies have been disabled for this discussion. Similar topics
2 posts
views
Thread by Fearless Freep |
last post: by
|
4 posts
views
Thread by R.Marquez |
last post: by
|
1 post
views
Thread by Chris Auer |
last post: by
|
2 posts
views
Thread by Raj |
last post: by
|
5 posts
views
Thread by Tony Clark |
last post: by
|
4 posts
views
Thread by Dale |
last post: by
|
9 posts
views
Thread by Chuck Anderson |
last post: by
|
3 posts
views
Thread by NickP |
last post: by
|
reply
views
Thread by abc123456 |
last post: by
|
9 posts
views
Thread by pek |
last post: by
| | | | | | | | | | |