Transparent image manipulation with GD2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Josip Maslaæ

    Transparent image manipulation with GD2

    Hello.

    My task/problem is this:
    I've made a script that takes images (in gif,jpg & png) and makes their
    thumbs in jpg format. Now, the problem is if I have a transparent gif when
    saved to jpg the part of the original picture that is transparent turns
    black in the new thumb. My question is: how can I define that the
    transparent part gets the color i want it to get (white is what i need) ?


    Actually, I now what in theory should be done - I should change the r,g,b
    values of the color that has aplha=127 (and that's not a problem with
    imagecolorset() ), but also I should change the alpha of that color to 0 -
    how can that be done ?
    My quess is that that is the right way to do it, but I'm open to suggestions
    ?!?


    btw, I've solved that problem like this (but there must be a better way???):
    i allocate new color with:
    $color = imagecoloralloc ate($image, $r, $g, $b);
    and then every pixel in the original picture that has alpha=127 I color
    with that new color:
    imagesetpixel($ image,$x,$y,$co lor);

    but, this is quite slow.


    thanks.














  • CountScubula

    #2
    Re: Transparent image manipulation with GD2

    "Josip Maslaæ" <josip.maslac@f er.hr> wrote in message news:<bsmcsb$e0 p$1@sunce.iskon .hr>...[color=blue]
    > Hello.
    >
    > My task/problem is this:
    > I've made a script that takes images (in gif,jpg & png) and makes their
    > thumbs in jpg format. Now, the problem is if I have a transparent gif when
    > saved to jpg the part of the original picture that is transparent turns
    > black in the new thumb. My question is: how can I define that the
    > transparent part gets the color i want it to get (white is what i need) ?
    >[/color]

    try creating a new image of thumb size, and color the background

    $im = imagecreate(bla .....);
    $background_col or = imagecoloralloc ate ($im, 255, 255, 255);
    imagefill($img, 0,0);

    then copy your source image onto this white thumbnail.


    Mike Bradley
    http://gzen.myhq.info -- free online php tools

    Comment

    Working...