Re: Transparent image

From: Michael Fuhr (mfuhr_at_fuhr.org)
Date: 11/29/03


Date: 28 Nov 2003 22:14:00 -0700


"AMcD" <arnold.mcdonald@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/


Relevant Pages

  • Re: Transparent Picture Box Control
    ... I've just had a look at that code and it uses a standard VB UserControl (with its BackStyle property set to Transparent) to achieve transparency, and it uses the standard VB PaintPicture method to draw the desired image into a hidden VB Autoredraw Picture Box so that it ends up with the drawn image in the Image property of the Autoredraw Picture Box. ... By the way, as a sort of footnote, using UserControls to create transparent "sprites" in this way does make it very easy to draw and animate them on your Form, because the UserControl looks after the drawing and the transparency and your code simply needs to set the Left and Top properties to appropriate values at run time to move the sprites around. ...
    (microsoft.public.vb.general.discussion)
  • Re: GIF image on a form
    ... Protected Overrides Sub OnPaintBackground ... better off looking for some picture control to take care of that for you. ... Just use DrawImage to render your GIF on the control ... The GIF has a transparent background. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Transparent color in GIF ignored
    ... Although treating gif transparent colors properly would be easier to use... ... > Using Picture Masks ... To keep certain white areas of your .bmp ...
    (microsoft.public.fox.programmer.exchange)
  • Re: GIF image on a form
    ... Protected Overrides Sub OnPaintBackground ... better off looking for some picture control to take care of that for you. ... Just use DrawImage to render your GIF on the control ... The GIF has a transparent background. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: GIF image on a form
    ... Protected Overrides Sub OnPaintBackground ... better off looking for some picture control to take care of that for you. ... Just use DrawImage to render your GIF on the control ... The GIF has a transparent background. ...
    (microsoft.public.dotnet.languages.vb)