Hello, in general, there is a function to save jpg images

if(exif_imagetype($tmp) == IMAGETYPE_JPEG) { $image = imagecreatefromjpeg($tmp); $path = $this->createdir().$name.'.jpg'; imagejpeg($image, $this->cdndir.$path, 100); imagedestroy($image); } 

and here is the same, but for gif

 if(exif_imagetype($tmp) == IMAGETYPE_GIF && $this->gif) { header("Content-Type: image/gif"); $image = imagecreatefromgif($tmp); $path = $this->createdir().$name.'.gif'; imagegif($image, $this->cdndir.$path); imagedestroy($image); } 

but the fact is that when saving, the picture then has the .gif extension and type, but the animation completely disappears and it becomes static, do not tell me what kind of nonsense? no nerves anymore

  • it is not nonsense. So it works. When resizing identity similar problems. Even in the animated gifs, "does, uses," not as pictures, but as documents. And from what do you create (recreate) gifs? Maybe AFTER checks for joining, move them to the storage location, and in the browser scale their width and height. BUT how to properly resize the animation, I do not know. Maybe there is a corresponding php-library? - root_x Povierennyy

2 answers 2

Can it be better to use move_uploaded_file ( https://secure.php.net/manual/ru/function.move-uploaded-file.php )?

  if (fileformat == XX and filesize == YY and ... ΠΏΡ€ΠΎΡ‡ΠΈΠ΅ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ){ if (! move_uploaded_file($tmp, "$cdndir/$newname")){ echo 'file not saved'; exit; } }else{ echo 'file is not image'; //ΠΈΠ»ΠΈ Π½Π΅ ΠΏΡ€ΠΎΡˆΠ΅Π» ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΡƒ ΠΏΠΎ ΠΈΠ½Ρ‹ΠΌ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ€Ρ‚Π°ΠΌ (Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ слишком большой) exit; } 

    The fact is that imagecreatefromgif saves only the first frame.

    Perhaps you will be helped by file_get_contents and file_put_contents

     $gif_image = file_get_contents("<URL Π°Π½ΠΈΠΌΠ°Ρ†ΠΈΠΈ>"); header("Content-Type: image/gif"); echo $gif_image; 

    PS Or go some library to save the animation :)