storing frames of animated gif while resizing
<p>i have a page where users can upload there photo that photo will be resized while uploading to server . i am using php to resize the images but the problem is when users upload animated gifs the animation is getting lost and when i checked i found that frames are not being stored   in server . so is there anyway we can store frames as well using php so that resized image with animation can be shown.in addition how to identify whether the image being uploaded by users is animated or not using php.</p>

<pre><code>class resizeimage{
var $type;
var $width;
var $height;
var $resize_width;
var $resize_height;
var $cut;
var $srcimg;
var $dstimg;
var $im;

var $fill;

function resizeimage($img, $image_type, $target, $wid, $hei,$c = 0, $qu = 75, $fill = '')
{
    $this-&gt;srcimg = $img;
            $this-&gt;fill = $fill;
    $this-&gt;resize_width = $wid;
    $this-&gt;resize_height = $hei;
    $this-&gt;cut = $c;
    if (eregi("jpg",$image_type) || eregi("jpeg",$image_type)) {
        $this-&gt;type="jpg";
    }

    elseif (eregi("gif",$image_type)) {
        $this-&gt;type="gif";
    }

    elseif (eregi("png",$image_type) || eregi("png",$image_type)) {
        $this-&gt;type="png";
    }

    else {
        echo "Not Supported File";
        exit();
    }
    $this-&gt;initi_img();
    $this -&gt; dst_img($target);
    $this-&gt;width = imagesx($this-&gt;im);
    $this-&gt;height = imagesy($this-&gt;im);
    // add by stan
    if (!$this-&gt;resize_height) {
        $this-&gt;resize_height = $this-&gt;resize_width*($this-&gt;height/$this-&gt;width);
    }
    if (!$this-&gt;resize_width) {
        $this-&gt;resize_width = $this-&gt;resize_height*($this-&gt;width/$this-&gt;height);
    }
    $this-&gt;newimg($qu);
    ImageDestroy ($this-&gt;im);
}
function newimg($qu)
{
    $resize_ratio = ($this-&gt;resize_width)/($this-&gt;resize_height);
    $ratio = ($this-&gt;width)/($this-&gt;height);
    if ($ratio&gt;=$resize_ratio) {
        $offset_x = 0;
        $offset_y = ceil(($this-&gt;resize_height - $this-&gt;resize_width/$ratio)/2);
        $copy_width = $this-&gt;resize_width;
        $copy_height = $this-&gt;resize_height/$ratio;
    }
    else {
        $offset_y = 0;
        $offset_x = ceil(($this-&gt;resize_width-$this-&gt;resize_height*$ratio)/2);
        $copy_width = $this-&gt;resize_height*$ratio;
        $copy_height = $this-&gt;resize_height;
    }
    if(($this-&gt;cut)=="1")
    {
        if($ratio&gt;=$resize_ratio)
        {
            $newimg = imagecreatetruecolor($this-&gt;resize_width,$this-&gt;resize_height);
            imagecopyresampled($newimg, $this-&gt;im, 0, 0, 0, 0, $this-&gt;resize_width,$this-&gt;resize_height, (($this-&gt;height)*$resize_ratio), $this-&gt;height);
            ImageJpeg ($newimg,$this-&gt;dstimg,$qu);
        }
        if($ratio&lt;$resize_ratio)
        {
            $newimg = imagecreatetruecolor($this-&gt;resize_width,$this-&gt;resize_height);
            imagecopyresampled($newimg, $this-&gt;im, 0, 0, 0, 0, $this-&gt;resize_width, $this-&gt;resize_height, $this-&gt;width, (($this-&gt;width)/$resize_ratio));
            ImageJpeg ($newimg,$this-&gt;dstimg,$qu);
        }
    }
    else
    {
        if ($this-&gt;fill == 'black') {
            $newimg = imagecreatetruecolor($this-&gt;resize_width,$this-&gt;resize_height);
            $bg = imagecolorallocate($newimg, 0, 0, 0);
            imagefill($newimg, 0, 0, $bg);
            imagecopyresampled($newimg, $this-&gt;im, $offset_x, $offset_y, 0, 0, $copy_width, $copy_height, $this-&gt;width, $this-&gt;height);
            ImageJpeg ($newimg,$this-&gt;dstimg,$qu);
        }
        elseif ($this-&gt;fill == 'white') {
            $newimg = imagecreatetruecolor($this-&gt;resize_width,$this-&gt;resize_height);
            $bg = imagecolorallocate($newimg, 255, 255, 255);
            imagefill($newimg, 0, 0, $bg);
            imagecopyresampled($newimg, $this-&gt;im, $offset_x, $offset_y, 0, 0, $copy_width, $copy_height, $this-&gt;width, $this-&gt;height);
            ImageJpeg ($newimg,$this-&gt;dstimg,$qu);
        }
        elseif($ratio&gt;=$resize_ratio)
        {
            $newimg = imagecreatetruecolor($this-&gt;resize_width,($this-&gt;resize_width)/$ratio);
            imagecopyresampled($newimg, $this-&gt;im, 0, 0, 0, 0, $this-&gt;resize_width, ($this-&gt;resize_width)/$ratio, $this-&gt;width, $this-&gt;height);
            ImageJpeg ($newimg,$this-&gt;dstimg,$qu);
        }
        elseif($ratio&lt;$resize_ratio)
        {
            $newimg = imagecreatetruecolor(($this-&gt;resize_height)*$ratio,$this-&gt;resize_height);
            imagecopyresampled($newimg, $this-&gt;im, 0, 0, 0, 0, ($this-&gt;resize_height)*$ratio, $this-&gt;resize_height, $this-&gt;width, $this-&gt;height);
            ImageJpeg ($newimg,$this-&gt;dstimg,$qu);
        }
    }
}
function initi_img()
{
    if($this-&gt;type=="jpg")
    {
        if (!$this-&gt;im = imagecreatefromjpeg($this-&gt;srcimg))
            die('This is not a pic:'.$this-&gt;srcimg);
    }
    if($this-&gt;type=="gif")
    {
        if (!$this-&gt;im = imagecreatefromgif($this-&gt;srcimg))
            die('This is not a pic:'.$this-&gt;srcimg);
    }
    if($this-&gt;type=="png")
    {
        if (!$this-&gt;im = imagecreatefrompng($this-&gt;srcimg))
            die('This is not a pic:'.$this-&gt;srcimg);
    }
}
function dst_img($target)
{
    $full_length  = strlen($this-&gt;srcimg);
    $type_length  = strlen($this-&gt;type);
    $name_length  = $full_length-$type_length;
    $name         = substr($this-&gt;srcimg,0,$name_length-1);
    $this-&gt;dstimg = $target.".".$this-&gt;type;
}

function type() {
    return $this-&gt;type;
}}
</code></pre>

<p>please give suggestion</p>
