Transparent GIF

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Trevor

    Transparent GIF

    This code is used to resize and then copy a GIF. How do I make it
    preserve transparency info?

    elseif ($_FILES['imagefile']['type'] == "image/gif") {
    list($width, $height, $type, $attr) =
    getimagesize($_ FILES['imagefile']['tmp_name']);

    if ($width >= $height) {
    if ($width > 200) {
    $ratio = 200/$width;
    $image_p = imagecreatetrue color(200, $height*$ratio) ;
    $image = imagecreatefrom gif($_FILES['imagefile']['tmp_name']);
    $newimage = imagecopyresamp led($image_p, $image, 0, 0, 0, 0, 200,
    $height*$ratio, $width, $height);
    imagepng($image _p, "image.png" );
    $image = "image.png" ;
    } else {
    copy ($_FILES['imagefile']['tmp_name'], "image.gif" );
    $image = "image.gif" ;
    }
    } else {
    if ($height > 134) {
    $ratio = 134/$height;
    $image_p = imagecreatetrue color($width*$r atio, 134);
    $image = imagecreatefrom gif($_FILES['imagefile']['tmp_name']);
    $newimage = imagecopyresamp led($image_p, $image, 0, 0, 0, 0,
    $width*$ratio, 134, $width, $height);
    imagepng($image _p, "image.png" );
    $image = "image.png" ;
    } else {
    copy ($_FILES['imagefile']['tmp_name'], "image.gif" );
    $image = "image.gif" ;
    }

  • Fred Forsyth

    #2
    Re: Transparent GIF

    I suspect you need to use "n = ImageColorTrans parent($image)" to read
    the colour used in the old image, and then
    "ImageColorTran sparent($image_ p, n)" to set in the new one. I've not
    checked it myself.

    Hope that helps
    Fred.

    Comment

    • Trevor

      #3
      Re: Transparent GIF

      $image = imagecreatefrom gif($_FILES['imagefile']['tmp_name']);

      Will $image retain transparency info in the code above?

      Comment

      Working...