Image Compression Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AMT India
    New Member
    • Feb 2007
    • 64

    Image Compression Problem

    I have an image resizing function using GD Library in php.After resizing the gif images,they lose their animation properties.
    [code=php]

    $file_name_src = $upload_file;
    $file_desinatio n2 = $compressedPath ;

    list($width_ori g, $height_orig, $type) = getimagesize($f ile_name_src);


    if($type == "1" )
    {
    $image = imagecreatefrom gif($file_name_ src);

    }
    elseif ($type=="2")
    {
    $image = imagecreatefrom jpeg($file_name _src);
    }
    elseif($type==" 3")
    {
    $image = imagecreatefrom png($file_name_ src);
    }
    //echo $image."<br/>";
    $new_width = $new_width;
    $new_height = $new_height;

    if ($new_width && ($width_orig < $height_orig))
    {
    $new_width = ($new_height / $height_orig) * $width_orig;
    }
    else
    {

    $new_height = ($new_width / $width_orig) * $height_orig;
    }





    // Resample
    $image_p = imagecreatetrue color($new_widt h, $new_height);

    //echo $image_p."<br/>";
    imagecopyresamp led($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);

    //echo $file_desinatio n2;



    if (function_exist s("imagegif") )
    {
    //header("Content-type: image/gif");
    imagegif($image _p,$file_desina tion2);
    }
    elseif (function_exist s("imagejpeg" ))
    {
    imagejpeg($imag e_p, $file_desinatio n2, 100);
    }
    elseif (function_exist s("imagepng") )
    {
    imagepng($image _p,$file_desina tion2);
    }
    elseif (function_exist s("imagewbmp" ))
    {
    imagewbmp($imag e_p,$file_desin ation2);
    }
    else
    {
    die("No image support in this PHP server");

    }
    imagedestroy($i mage_p);
    chmod($file_des ination2,0655);

    return true;
    [/code]

    Regards,
    AMTIndia
Working...