Ask a Question related to PHP Development, Design and Development.
-
AMcD #1
Transparent image
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.
AMcD Guest
-
transparent background for logo w/ image
recently had to auto trace/draw a logo which was not vector. after recreating the image and coloring accordingly, i added text above, below and... -
Import a Transparent Image
I need to import an image with transparency. Freehand Help states that transparency is lost when you import a GIF file. Does anyone know a way... -
How to make an image interactive transparent
I want my image to be interactively transparent. Corel PhotoPaint offers simple tool to give this effect. This means, I want my image to fade from... -
Transparent Image Woes
I am having difficulty using Photoshop 7's Export Transparent Image feature. No matter what combination I choose, when I place the finished image... -
How do I make an image more transparent so I can....
I know this one!! (First make sure you're working on a copy of our image - you don't want ever want to mess up your only original.) Open the... -
Michael Fuhr #2
Re: Transparent image
"AMcD" <arnold.mcdonald@free.fr> writes:
This isn't related to your problem, but are you familiar with the> <?php
> Header('Content-type: image/png');
>
> $sz = "";
> $FileValue = 1000;
> $i = strlen($FileValue);
> for ( $j = 0; $j < 7-$i; $j++ )
> {
> $sz = $sz . "0";
> }
sprintf() function? You're going to a lot of trouble to add leading
zeros when you could just do this:
$str = sprintf("%07d", $FileValue);
Create the first image with imagecreatetruecolor() and then create> $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.
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
[url]http://www.fuhr.org/~mfuhr/[/url]
Michael Fuhr Guest
-
R. Rajesh Jeba Anbiah #3
Re: Transparent image
"AMcD" <arnold.mcdonald@free.fr> wrote in message news:<3fc78861$0$17110$626a54ce@news.free.fr>...
<snip>> Hi!
>
I get aThe transparent support for PNG is broken in many browsers.> rotated picture, but not transparent. How to solve that? I've used a plenty
> of tricks, no one works.
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
R. Rajesh Jeba Anbiah Guest
-
Michael Fuhr #4
Re: Transparent image
[email]ng4rrjanbiah@rediffmail.com[/email] (R. Rajesh Jeba Anbiah) writes:
The OP stated that the transparent background works for the original> "AMcD" <arnold.mcdonald@free.fr> wrote in message news:<3fc78861$0$17110$626a54ce@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.
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
[url]http://www.fuhr.org/~mfuhr/[/url]
Michael Fuhr Guest
-
AMcD #5
Re: Transparent image
Michael Fuhr wrote:
Err, it was just a quick sample ;o). But thanx for the comment (I'm just> 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);
starting with PHP).
OK, then, you mean a stuff like that?> 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.
<?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.
AMcD Guest
-
AMcD #6
Re: Transparent image
R. Rajesh Jeba Anbiah wrote:
Not this way dude. All browsers I'm using support transparency and when I> The transparent support for PNG is broken in many browsers.
> Search the net for more about the politics, workaround, and supporting
> broswers, etc.
display the "horizontal" transparent PNG picture, there is no problem. I
suspect GD 1.8 instead...
Thanx for helping.
AMcD Guest
-
Michael Fuhr #7
Re: Transparent image
"AMcD" <arnold.mcdonald@free.fr> writes:
Don't use $sz.$FileValue here -- sprintf() has already put the value> 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);
with leading zeros in $sz. You're displaying "00050005000", although
you probably don't see that because the image isn't big enough.
Sorry I didn't qualify my previous answer: I'm using GD 2.0.15.> $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.
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
[url]http://www.fuhr.org/~mfuhr/[/url]
Michael Fuhr Guest



Reply With Quote

