How to concatenate icons into a single image with

2019-01-31 07:18发布

问题:

I want to use CSS sprites on a web site instead of separate image files, for a large collection of small icons that are all the same size. How can I concatenate (tile) them into one big image using ImageMagick?

回答1:

From the page you linked, 'montage' is the tool you want. It'll take a bunch of images and concatenate/tile them into a single output. Here's an example image I've made before using the tool: alt text http://davr.org/ds2/demos2/index.png



回答2:

convert works much better than montage. It arranges images vertically or horizontally and keeps png transparency.

convert *.png -append sprites.png (append vertically)
convert *.png +append sprites.png (append horizontally)


回答3:

You are looking for:

montage -background transparent -geometry +4+4 *.png sprite.gif


回答4:

I like this script for automatical sprite/css generation. "Building CSS sprites with Bash & Imagemagick"

  • article copy in Waybackmashine https://web.archive.org/web/20150529041037/http://jaymz.eu/blog/2010/05/building-css-sprites-with-bash-imagemagick

  • script copy http://blog.kupriyanov.com/2011/01/solvedbuilding-css-sprites-with-bash.html