Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default Re: Transparent image

    "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
    [url]http://www.fuhr.org/~mfuhr/[/url]
    Michael Fuhr Guest

  4. #3

    Default Re: Transparent image

    "AMcD" <arnold.mcdonald@free.fr> wrote in message news:<3fc78861$0$17110$626a54ce@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
    R. Rajesh Jeba Anbiah Guest

  5. #4

    Default Re: Transparent image

    [email]ng4rrjanbiah@rediffmail.com[/email] (R. Rajesh Jeba Anbiah) writes:
    > "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.
    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
    [url]http://www.fuhr.org/~mfuhr/[/url]
    Michael Fuhr Guest

  6. #5

    Default Re: Transparent image

    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.


    AMcD Guest

  7. #6

    Default Re: Transparent image

    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 Guest

  8. #7

    Default Re: Transparent image

    "AMcD" <arnold.mcdonald@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
    [url]http://www.fuhr.org/~mfuhr/[/url]
    Michael Fuhr Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139