Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何制作GIF图像的动画缩略图?_Php_Gd_Thumbnails - Fatal编程技术网

Php 如何制作GIF图像的动画缩略图?

Php 如何制作GIF图像的动画缩略图?,php,gd,thumbnails,Php,Gd,Thumbnails,我尽了一切努力为缩略图制作动画GIF,但失败了。如果原始图像是动画GIF,如何使缩略图也成为动画?我正在使用PHP和GD库 这是我的缩略图PHP代码: function upload_thumb($photo_dest, $file_maxdim = "60") { // SET DESIRED WIDTH AND HEIGHT $x = 0; $y = 0; $width = $this->file_width; $height = $

我尽了一切努力为缩略图制作动画GIF,但失败了。如果原始图像是动画GIF,如何使缩略图也成为动画?我正在使用PHP和GD库

这是我的缩略图PHP代码:

function upload_thumb($photo_dest, $file_maxdim = "60") {
      // SET DESIRED WIDTH AND HEIGHT
    $x = 0;
    $y = 0;
      $width = $this->file_width;
      $height = $this->file_height;
      if($width > $height)
    { 
        $x = ceil(($width - $height) / 2);
        $width = $height;
      }
    elseif($width < $height)
    {
        $y = ceil(($height - $width) / 2);
        $height = $width;
      }

      // RESIZE IMAGE AND PUT IN USER DIRECTORY
      switch($this->file_ext)
    {
        case "gif":
        case "x-gif";
          $file = imagecreatetruecolor($file_maxdim, $file_maxdim);
          $new = imagecreatefromgif($this->file_tempname);
          $kek=imagecolorallocate($file, 255, 255, 255);
          imagefill($file,0,0,$kek);
          imagecopyresampled($file, $new, 0, 0, $x, $y, $file_maxdim, $file_maxdim, $width, $height);
          imagegif($file, $photo_dest, 100);
          ImageDestroy($new);
          ImageDestroy($file);
          break;

        case "bmp":
          $file = imagecreatetruecolor($file_maxdim, $file_maxdim);
          $new = $this->imagecreatefrombmp($this->file_tempname);
          for($i=0; $i<256; $i++) { imagecolorallocate($file, $i, $i, $i); }
          imagecopyresampled($file, $new, 0, 0, $x, $y, $file_maxdim, $file_maxdim, $width, $height); 
          imagejpeg($file, $photo_dest, 100);
          ImageDestroy($new);
          ImageDestroy($file);
          break;

        case "jpeg":
        case "jpg":
          $file = imagecreatetruecolor($file_maxdim, $file_maxdim);
          $new = imagecreatefromjpeg($this->file_tempname);
          for($i=0; $i<256; $i++) { imagecolorallocate($file, $i, $i, $i); }
          imagecopyresampled($file, $new, 0, 0, $x, $y, $file_maxdim, $file_maxdim, $width, $height);
          imagejpeg($file, $photo_dest, 100);
          ImageDestroy($new);
          ImageDestroy($file);
          break;

        case "png":
        case "apng";
        case "x-png";
        $photo_dest=strtolower($photo_dest);
        $photo_dest=str_replace("jpg","png",$photo_dest);
        $file = imagecreatetruecolor($width, $height);
        $new = imagecreatefrompng($this->file_tempname);
        imagealphablending($file,false);
        imagesavealpha($file,true);
        $transparent = imagecolorallocatealpha($file, 255, 255, 255, 127);
        imagefilledrectangle($file, 0, 0, $width, $height, $transparent);
        imagecopyresampled($file, $new, 0, 0, 0, 0, $width, $height, $this->file_width, $this->file_height);
        imagepng($file, $photo_dest);
        ImageDestroy($new);
        ImageDestroy($file);
        break;
      } 

      chmod($photo_dest, 0777);

      return true;
    }
function upload\u thumb($photo\u dest,$file\u maxdim=“60”){
//设置所需的宽度和高度
$x=0;
$y=0;
$width=$this->file\u width;
$height=$this->file\u height;
如果($width>$height)
{ 
$x=天花板($width-$height)/2);
$width=$height;
}
elseif($宽度<$高度)
{
$y=天花板($height-$width)/2);
$height=$width;
}
//调整图像大小并放入用户目录
开关($this->file\u ext)
{
案例“gif”:
案例“x-gif”;
$file=imagecreatetruecolor($file\u maxdim,$file\u maxdim);
$new=imagecreatefromformgif($this->file\u tempname);
$kek=imagecolorallocate($file,255,255);
imagefill($file,0,0,$kek);
imagecopyresampled($file、$new、0、0、$x、$y、$file\u maxdim、$file\u maxdim、$width、$height);
imagegif($file,$photo\u dest,100);
(新的);
图像销毁($文件);
打破
案例“bmp”:
$file=imagecreatetruecolor($file\u maxdim,$file\u maxdim);
$new=$this->imagecreatefromfrombmp($this->file\u tempname);
对于($i=0;$i文件名);
对于($i=0;$i文件名);
imagealphabling($file,false);
imagesavealpha($file,true);
$transparent=imagecolorallocatealpha($file,255,255,127);
imagefilledrectangle($file,0,0,$width,$height,$transparent);
imagecopyresampled($file,$new,0,0,0,0,$width,$height,$this->file\u width,$this->file\u height);
imagepng($file,$photo\u dest);
(新的);
图像销毁($文件);
打破
} 
chmod($photo_dest,0777);
返回true;
}
Link 1:Link 2:try gdenhancer