我正在编写一个 shell 脚本来确定是否可以通过将这些大型 GIF 转换为 JPG 来缩小文件大小以供网络使用。这个 GIF 给 带来了问题convert
。它生成了 15 个版本的 GIF。我convert
再次使用 -verbose 选项运行该命令,但我不明白为什么它对待这个 GIF 的方式与其他 GIF 不同,以及为什么它会生成 15 个版本。
GIF 只有 11K,所以我并不担心将此特定文件转换为 JPEG,因为它已经足够小了,但我试图理解为什么convert
会出现这种情况。我是不是用错了?
正在运行的命令convert
:
# convert -verbose Images/made_with_mac.gif /tmp/analyze_images/Images/made_with_mac.jpg
Images/made_with_mac.gif[0] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.009
Images/made_with_mac.gif[1] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[2] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[3] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[4] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[5] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[6] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[7] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[8] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[9] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[10] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[11] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[12] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[13] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif[14] GIF 88x31 88x31+0+0 8-bit sRGB 256c 11.4KB 0.000u 0:00.000
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-0.jpg[0] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.44KB 0.010u 0:00.010
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-1.jpg[1] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.36KB 0.010u 0:00.010
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-2.jpg[2] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.25KB 0.010u 0:00.010
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-3.jpg[3] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.22KB 0.010u 0:00.010
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-4.jpg[4] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.22KB 0.010u 0:00.010
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-5.jpg[5] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.28KB 0.010u 0:00.010
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-6.jpg[6] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.38KB 0.010u 0:00.010
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-7.jpg[7] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.41KB 0.010u 0:00.010
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-8.jpg[8] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.38KB 0.010u 0:00.010
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-9.jpg[9] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.28KB 0.010u 0:00.019
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-10.jpg[10] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.22KB 0.010u 0:00.019
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-11.jpg[11] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.22KB 0.020u 0:00.019
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-12.jpg[12] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.25KB 0.020u 0:00.019
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-13.jpg[13] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.36KB 0.020u 0:00.019
Images/made_with_mac.gif=>/tmp/analyze_images/Images/made_with_mac-14.jpg[14] GIF 88x31 88x31+0+0 8-bit sRGB 256c 2.4KB 0.020u 0:00.019
文件信息made_with_mac.gif
:
me@ubuntu:~/testdir$ file Images/made_with_mac.gif
Images/made_with_mac.gif: GIF image data, version 89a, 88 x 31
的目录列表Images/made_with_mac.gif
:
me@ubuntu:~/testdir$ ls -ls Images/made_with_mac.gif
12 -rw-rw-r-- 1 me me 11372 Dec 29 18:53 Images/made_with_mac.gif
sum
使用进行计数/tmp/analyze_images/Images/
:
me@ubuntu:~/testdir$ sum /tmp/analyze_images/Images/* | sort
11875 3 /tmp/analyze_images/Images/made_with_mac-13.jpg
11875 3 /tmp/analyze_images/Images/made_with_mac-1.jpg
21853 3 /tmp/analyze_images/Images/made_with_mac-6.jpg
21853 3 /tmp/analyze_images/Images/made_with_mac-8.jpg
28311 3 /tmp/analyze_images/Images/made_with_mac-12.jpg
28311 3 /tmp/analyze_images/Images/made_with_mac-2.jpg
34223 3 /tmp/analyze_images/Images/made_with_mac-0.jpg
41967 3 /tmp/analyze_images/Images/made_with_mac-14.jpg
47849 3 /tmp/analyze_images/Images/made_with_mac-5.jpg
47849 3 /tmp/analyze_images/Images/made_with_mac-9.jpg
48702 3 /tmp/analyze_images/Images/made_with_mac-11.jpg
48702 3 /tmp/analyze_images/Images/made_with_mac-3.jpg
49836 3 /tmp/analyze_images/Images/made_with_mac-10.jpg
49836 3 /tmp/analyze_images/Images/made_with_mac-4.jpg
65520 3 /tmp/analyze_images/Images/made_with_mac-7.jpg
目录列表/tmp/analyze_images/Images/
:
me@ubuntu:~/testdir$ ls -ls /tmp/analyze_images/Images/*
4 -rw-rw-r-- 1 me me 2439 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-0.jpg
4 -rw-rw-r-- 1 me me 2219 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-10.jpg
4 -rw-rw-r-- 1 me me 2222 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-11.jpg
4 -rw-rw-r-- 1 me me 2249 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-12.jpg
4 -rw-rw-r-- 1 me me 2360 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-13.jpg
4 -rw-rw-r-- 1 me me 2404 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-14.jpg
4 -rw-rw-r-- 1 me me 2360 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-1.jpg
4 -rw-rw-r-- 1 me me 2249 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-2.jpg
4 -rw-rw-r-- 1 me me 2222 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-3.jpg
4 -rw-rw-r-- 1 me me 2219 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-4.jpg
4 -rw-rw-r-- 1 me me 2281 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-5.jpg
4 -rw-rw-r-- 1 me me 2384 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-6.jpg
4 -rw-rw-r-- 1 me me 2412 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-7.jpg
4 -rw-rw-r-- 1 me me 2384 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-8.jpg
4 -rw-rw-r-- 1 me me 2281 Jan 10 11:36 /tmp/analyze_images/Images/made_with_mac-9.jpg
答案1
这是made_with_mac.gif
动画 GIF 吗?如果是,当您将其转换为 JPEG 时,它只是截取 GIF 的每一帧并将它们分别保存为 JPEG 图像。
如果你想避免这种情况,那么有几种解决方案:
您可以添加
-flatten
该命令的选项用于将帧拼合为一个图像:convert -flatten -verbose Images/made_with_mac.gif /tmp/analyze_images/Images/made_with_mac.jpg
您可以添加
-mosiac
该命令基于 GIF 的帧创建马赛克 JPEG 图像的选项:convert -mosaic -verbose Images/made_with_mac.gif /tmp/analyze_images/Images/made_with_mac.jpg
或者您甚至可以选择要保存为 JPEG 的动画 GIF 的一帧,像这样;请注意,此示例命令将获取 GIF 的第 7 帧并将其保存为 JPEG:
convert -verbose Images/made_with_mac[7].gif /tmp/analyze_images/Images/made_with_mac7.jpg