Animasyon bozmadan animasyonlu gif dosyası yeniden boyutlandırma

8 Cevap php

Ben animasyon bozmadan bir animasyonlu gif dosyası yeniden boyutlandırmak gerekir.

Nasıl PHP bunu kullanarak yapabilirim?

8 Cevap

Eğer imagemagick erişiminiz varsa, bunu yapabilirsiniz:

system("convert big.gif -coalesce coalesce.gif");
system("convert -size 200x100 coalesce.gif -resize 200x10 small.gif");

Eğer sistem () erişiminiz yoksa, bu büyük olasılıkla mümkün imagemagick eklentisi ile

NOT: Bu nedeniyle aslında görüntüyü deoptimizing kaynaştırma için daha küçük boyutları görüntü olsa daha büyük bir dosya boyutu yaratabilir.

UPDATE: If you don't have ImageMagick access, you should be able to use a combination of the following steps to resize an animated gif (assuming you have GD access):

  1. Görüntü animasyonlu gif olup olmadığını tespit: Can I detect animated gifs using php and gd? (üst cevap)
  2. Tek kare içine animasyonlu gif bölmek: http://www.phpclasses.org/package/3234-PHP-Split-GIF-animations-into-multiple-images.html
  3. Kareleri tek tek yeniden boyutlandırma: http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/
  4. Yine animasyonlu gif içine kareleri Recomposite: http://www.phpclasses.org/package/3163-PHP-Generate-GIF-animations-from-a-set-of-GIF-images.html

Bu kesinlikle çok daha yoğun ImageMagick yol daha, ama teknik olarak mümkün olmalıdır.

Eğer çalışma alırsanız, dünya ile paylaşın lütfen!

http://www.gdenhancer.com Bu sadece GD Kütüphanesi ihtiyaç ve gif animasyon tutmak GDEnhancer deneyin

Lütfen çerçeve zamanlamasını koruyarak üzerinde örnek http://www.php.net/manual/en/imagick.coalesceimages.php gif yeniden boyutlandırmak. Diğer örneklerin çoğu yapmazsanız bir şey.

Diğer örnekler, rebuild gif bu görüntünün modify çerçevelerine izin verir iken.

Ben bir torba içinde bu var bence.

Hiçbir mükemmel anlamına gelir ve orada burada bazı kaba kuvvet içerir, ama ben animasyonlar desteklemek için yeterli işlevsellik tabanlı resim boyutlandırma komut benim GD / PHP eklemek mümkün bu bir çözümdür.

http://www.phpclasses.org/browse/author/283569.html - çözüm ağır László Zsidi tarafından mükemmel bir ücretsiz arşivlerine dayanıyor

Eğer hızlı bir demo kontrol ve http://forssto.com/gifexample/ adlı kaynaklardan indirebilirsiniz (doğrudan bağlantı: http://forssto.com/gifexample/gifanimresize.zip)

BİLİNEN SORUNLAR:

  • Transparency support - this would be easy to append to this solution, but as I don't have an immediate need for this, I'm stopping here.

  • Frame rate - for some unknown reason the GifEncoder class fails to take into account the frame rates specified. I'll need to look into this later.

  • I did find one gif file from my set of tests that somehow had different sized frames in it and that animation failed to work correctly. Still some debugging to do then.

I have tried numerous examples of resizing animated GIFs with Imagick PHP module, but none of them worked for me. Then after some debugging time at last I found the actual issue: the animation was lost upon saving image to disk, by $animation->writeImage($file_dst); or $animation->writeImages($file_dst, true);

I've changed it to file_put_contents($file_dst, $animation->getImagesBlob()); and most examples started working immediately.

Birine yardımcı olur umarım.

just creat 3 folder name 1.frame_output 2.images 3.resized_frame_output and download 2 encoder and decoder class from this below link 1.Download class "GIFDecoder.class.php" from http://phpclasses.elib.com/browse/package/3234.html 2.Download class "GIFEncoder.class.php" from http://phpclasses.betablue.net/browse/package/3163.html

ve sonra, "resize_animator.php" olarak betik adını çalıştırmak bir yükleme html dosyası ibaret & Senaryoyu keyfini olsun.

.. ..... Index.php olarak bu script kaydetmek .......

<html>
<body>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="resize_animator.php" method="post" enctype="multipart/form-data" >
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td align="center"><font face="Tahoma">SELECT ANIMATED FILE</font> 
<input type="file" name="uploadfile" size="20" accept="image/gif"/>
</td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="PROCESS ANIMATION" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>

........................ Kaydetmek ve bu script resize_animator.php gibi ............

   <?php

   require "GIFDecoder.class.php";
   include "GIFEncoder.class.php";
   $file_name= $_FILES['uploadfile']['name'];
   $file_ext = substr($file_name, -4);
   $file_size=($_FILES["uploadfile"]["size"] /1024 );
   if($file_ext=='.gif')
    {
 if($file_size > 0 && $file_size < 2000 )
  {
    session_start ( );
        $uploaded_file = $_FILES['uploadfile']['tmp_name'];
        $fp=file_get_contents($uploaded_file);

        if ( $fp )
            {
                $_SESSION['delays'] = Array ( );
                $gif = new GIFDecoder ( $fp );
                $arr = $gif->GIFGetFrames ( );
                $_SESSION [ 'delays' ] = $gif -> GIFGetDelays ( );

                for ( $i = 0; $i < count ( $arr ); $i++ )
                {
                        fwrite ( fopen ( ( $i < 10 ? "frame_output/$i$i_frame.gif" : "frame_output/$i_frame.gif" ), "wb" ), $arr [ $i ] );
                }
          }

        function resize_frames($newwidth,$newheight)
            {
                    $dir=opendir("frame_output/");
                    $i=0;
                    while($imgfile=readdir($dir))
                    {
                         if ($imgfile != "." && $imgfile!="..")
                             {
                                        $imgarray[$i]=$imgfile;
                                        $uploadedfile = "frame_output/".$imgarray[$i];
                                        $src = imagecreatefromgif($uploadedfile);
                                        list($width,$height)=getimagesize($uploadedfile);
                                        $tmp=imagecreatetruecolor($newwidth,$newheight);
                                        imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
                                        $filename = "resized_frame_output/".$imgarray[$i];
                                        imagegif($tmp,$filename,100);
                                        imagedestroy($src);
                                        imagedestroy($tmp);
                                        $i++;
                            }
                    }
                    closedir($dir);

                if ( $dh = opendir ( "resized_frame_output/" ) )
                {
                    while ( false !== ( $dat = readdir ( $dh ) ) )
                    {
                        if ( $dat != "." && $dat != ".." )
                        {
                            $frames [ ] = "resized_frame_output/$dat";
                        }
                    }
                    closedir ( $dh );
                }

            $gif = new GIFEncoder   ( $frames,$_SESSION [ 'delays' ],0, 2, 0, 0, 0,"url" );
            $data = $gif->GetAnimation ( );

            $x='x';
            $y='_';
            $uploaded_file_name= $_FILES['uploadfile']['name'];
            $actual_file_name = substr($uploaded_file_name, 0, -4);
            $file_extention = substr($uploaded_file_name, -4);
            $new_name=$actual_file_name.$y.$newwidth.$x.$newheight.$file_extention ;

            //$output_image_name=$newwidth.$x.$newheight;
            fwrite ( fopen ( "images/$new_name", "wb" ), $data );
            //remove resized frames from folder
            //sleep for 1 second
            // usleep(2000000);
            $dir = 'resized_frame_output/';
            foreach(glob($dir.'*.*') as $v)
                {
                 unlink($v);
                }
        }  // end of function resize_frames


            $gif = new GIFEncoder   ( $frames,$_SESSION [ 'delays' ],0, 2, 0, 0, 0,"url" );
            $data = $gif->GetAnimation ( );

            $x='x';
            $y='_';
            $z='_p';
            $uploaded_file_name= $_FILES['uploadfile']['name'];
            $actual_file_name = substr($uploaded_file_name, 0, -4);
            $file_extention = substr($uploaded_file_name, -4);
            $new_name=$actual_file_name.$y.$newwidth.$x.$newheight.$z.$file_extention ;

            //$output_image_name=$newwidth.$x.$newheight;
            fwrite ( fopen ( "images/$new_name", "wb" ), $data );
            //remove resized frames from folder
            //sleep for 1 second
             //usleep(2000000);
            $dir = 'resized_frame_output/';
            foreach(glob($dir.'*.*') as $v)
                {
                 unlink($v);
                }
        }  // end of function resize_frames

            resize_frames(110,110);
            resize_frames(120,160);
            resize_frames(120,80);
            resize_frames(128,96);
            resize_frames(128,128);
            resize_frames(208,208);
            resize_frames(208,320);

            session_destroy();

            //usleep(200000);

            //remove resized frames from folder
            $dir = 'frame_output/';
            foreach(glob($dir.'*.*') as $v)
                {
                 unlink($v);
                }
      echo "<center><h1>Your Animation processing is compleated.</h1></center>";
      echo "<center><h2><a href=\"index.php\">BACK TO UPLOAD PAGE</h2></center>";
  }  //end of file size checker
else
 {
      echo "<center><h2>You Upload a unfit size image .Upload a file within 2000 KB</h2></center>";
      echo "<center><h2><a href=\"index.php\">BACK TO UPLOAD PAGE</h2></center>";
 }
   } //end of file extention checker
  else
  {
   echo "<center><h2>Uplaod a gif file!</h2></center>";
   echo "<center><h2><a href=\"index.php\">BACK TO UPLOAD PAGE</h2></center>";
  }
  ?>

....................... Enjoy Lets ............

iş bu folders.its gerekli değil içine ne görmek için usleep işlevi yorumsuz ama işlevselliğini görmek için kullanabilirsiniz.

Eğer sunucu imagemagick yok ise bunu denemek isteyebilirsiniz:

http://www.phpclasses.org/package/7353-PHP-Resize-animations-in-files-of-the-GIF-format.html

Sınıf GD ile GIF animasyonları yeniden boyutlandırma. İlk vb onun gecikme sürelerini, bertaraf yöntemleri, renk tabloları kaybetmeden tek bir dosya içine tekrar derler ondan sonra da, bunları yeniden boyutlandırır, çerçeveleri ayrıştırır

Deneyin ve bir hata bulmak veya vb bazı iyileştirmeleri önermek istiyorsanız sınıf 'forumu kullanın ya da benim web sayfasında bir yorum bırakabilirsiniz. Ve ben en kısa sürede cevap olacak.

Yalak Imagemagick dışında bu, tüm cevaplar benim için işe yaramadı. Önce bu cevapları komut tüm hataları ile dolu.

Hatta ImageMagick işte yönetmek zor yüklemeden benim deneyim.

Here is how to install ImageMagick on windows 7 and xampp 1.7.4.
Note: Choose 64 bit (for win7), and when installing leave checked the option "Add to system path".

And then follow: http://www.creativearmory.com/tutorials/resize-animated-gifs-with-php-and-imagemagick

Bu mesajların da komut saatlerce kaybetmiş ve ImageMagick ve bu öğretici dakika sucessfull oldu.

Ve bir not daha: benim webserver varsayılan ImageMagick var, bu yüzden sunucuların en çok o var sanırım.