在不破坏动画的情况下调整动画 GIF 文件的大小 [英] Resize animated GIF file without destroying animation

查看:43
本文介绍了在不破坏动画的情况下调整动画 GIF 文件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在不破坏动画的情况下调整动画 GIF 文件的大小.

I need to resize an animated GIF file without destroying the animation.

如何使用 PHP 来实现?

How can I do it using PHP?

推荐答案

如果你有 imagemagick 访问权限,你可以这样做:

if you have imagemagick access, you can do this:

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

如果您没有 system() 访问权限,这很可能使用 imagemagick 插件实现

this is most likely possible with the imagemagick plugin if you don't have system() access

注意:这可能会创建更大的文件大小,尽管图像尺寸较小,因为合并本质上会取消优化图像.

NOTE: this may create a larger filesize though a smaller dimensions image due to coalescing essentially deoptimizing the image.

更新:如果您没有 ImageMagick 访问权限,您应该能够使用以下步骤的组合来调整动画 gif 的大小(假设您有 GD 访问权限):

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. 检测图像是否为动画 gif:Can I使用 php 和 gd 检测动画 gif?(最佳答案)
  2. 将动画 gif 拆分为单独的帧:http://www.phpclasses.org/package/3234-PHP-Split-GIF-animations-into-multiple-images.html
  3. 调整单个框架的大小:http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/
  4. 再次将帧重新合成为动画 gif:http://www.phpclasses.org/package/3163-PHP-Generate-GIF-animations-from-a-set-of-GIF-images.html

这肯定比 ImageMagick 路线密集得多,但在技术上应该是可行的.

This is definitely much more intensive than the ImageMagick route, but it should be technically possible.

如果你成功了,请与全世界分享!

If you get it working, please share with the world!

这篇关于在不破坏动画的情况下调整动画 GIF 文件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆