Linux 如何在命令行中合并图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20075087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:23:32  来源:igfitidea点击:

How to merge images in command line?

linuximage-processingcommand-line

提问by Michael

I would like to try the CSS Spritetechnique to load a few thumbnails as a single image. So I need to "merge" a few thumbnails in a single file offline in the server.

我想尝试使用CSS Sprite技术将一些缩略图作为单个图像加载。所以我需要在服务器中离线“合并”单个文件中的几个缩略图。

Suppose I have 10 thumbnails of the same size. How would you suggest I "merge" them from Linux command line?

假设我有 10 个相同大小的缩略图。您如何建议我从 Linux 命令行“合并”它们?

采纳答案by Petr Mensik

You can also try ImageMagicwhich is great for creating CSS sprites. Some tutorial about it here.

您还可以尝试ImageMagic,它非常适合创建 CSS 精灵。一些关于它的教程在这里

Example (vertical sprite):

示例(垂直精灵):

convert image1.png image2.png image3.png -append result/result-sprite.png

Example (horizontal sprite):

示例(水平精灵):

convert image1.png image2.png image3.png +append result/result-sprite.png

回答by Alfe

Use the pnmcatof the netpbm-package.

使用pnmcatnetpbm-package 的 。

You probably have to convert your input files to and fro for using it:

您可能必须来回转换输入文件才能使用它:

pnmcat -lr <(pngtopnm 1.png) <(pngtopnm 2.png) | pnmtopng > all.png

回答by tjanez

You can also use GraphicsMagick, a lighter and faster fork of ImageMagick:

您还可以使用GraphicsMagick,它是 ImageMagick 的一个更轻、更快的分支:

gm convert image1.png image2.png -append combined.png

A simple time comparison of merging 12 images:

合并12张图片的简单时间对比:

time convert image{1..12}.jpg -append test.jpg

real    0m3.178s
user    0m3.850s
sys     0m0.376s

time gm convert image{1..12}.jpg -append test.jpg

real    0m1.912s
user    0m2.198s
sys     0m0.766s

GraphicsMagick is almost twice as fast as ImageMagick.

GraphicsMagick 的速度几乎是 ImageMagick 的两倍。

回答by abu_bua

If you prefer to merge the pictures from left to right, use the following command:

如果您更喜欢从左到右合并图片,请使用以下命令:

convert image{1..0}.png +append result/result-sprite.png

Note the +appendinstead of -append.

请注意+append代替-append