我已尝试过所有内容以获取缩略图的动画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;
}