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