Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:02:56+00:00 2026-05-31T04:02:56+00:00

i have a page where users can upload there photo that photo will be

  • 0

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.

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->srcimg = $img;
            $this->fill = $fill;
    $this->resize_width = $wid;
    $this->resize_height = $hei;
    $this->cut = $c;
    if (eregi("jpg",$image_type) || eregi("jpeg",$image_type)) {
        $this->type="jpg";
    }

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

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

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

function type() {
    return $this->type;
}}

please give suggestion

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:02:58+00:00Added an answer on May 31, 2026 at 4:02 am

    you can use the gif resizer class that i wrote with some modifications i think. The first mod you need to do is to keep the frames in the temp directory, because my script deletes them after it resizes the gif. Second, the animation may contain disposal method that when you split the animation to frames, you’d get just the difference of the image relative to the first frame. and you should merge the images first when you want the real (complete) frame.

    here’s the script url.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a subscription link on a page that the logged in users can
I have an upload form where users can upload images that are currently being
So I have a settings page, and the user can upload a photo to
I have a simple ASP.NET page that users can browse to, select a file
I have a pretty simple profile page where users can upload images and videos.
I have a web page on which users can upload text files (but a
I have a page where a user can upload a file along with some
I have a page where the user can dynamically add file upload boxes. Adding
I have a page where users can select different documents files in a datalist
I have a web page where users can see data from MongoDB on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.