Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.
Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Hide

Credits

Batch Convert SVG to PNG

Terminal - Batch Convert SVG to PNG
for i in *.svg; do convert "$i" "${i%.svg}.png" & done
2014-03-26 15:03:54
User: robinro
0
Batch Convert SVG to PNG

convert all *.svg to png _in parallel_

this speeds up the conversion for many files, but might also not be feasible for a large number of files

Alternatives

There are 5 alternatives - vote for the best!

Terminal - Alternatives
find . -name \*.svg -print0 | xargs -0 -n1 -P4 -I{} bash -c 'X={}; convert "$X" "${X%.svg}.png"'
2014-04-11 14:30:30
User: flatcap
Functions: bash find xargs
2

Convert some SVG files into PNG using ImageMagick's convert command.

Run the conversions in parallel to save time.

This is safer than robinro's forkbomb approach :-)

xargs runs four processes at a time -P4

for i in *.svg; do convert "$i" "${i%.svg}.png"; done
2014-03-24 14:02:02
User: flatcap
1

Convert some SVG files into PNG using ImageMagick's convert command.

svg2png(){ png="${1%.*}.png"; inkscape --export-png="$png" --without-gui "$1" && pngcrush -brute -rem alla -rem text "$png" "$png.new" && mv "$png.new" "$png";}
2013-05-08 15:21:52
Functions: mv
0

Convert an SVG to PNG and then crush the filesize brutally with pngcrush. Good for icons and website junk that you want to keep small, expecially before base64 encoding.

Uses inkscape, not imagemagick, as IM doesn't always handle gradients well. This way also seems to sometime save some file size (eg. 619 with Inkscape compared to 695 with IM).

IM can do general images:

img2png(){ png="${1%.*}.png"; convert -background none "$1" "$png" && pngcrush -brute -rem alla -rem text "$png" "$png.new" && mv "$png.new" "$png"; }
parallel convert {} {.}.png ::: *.svg
2014-04-12 06:39:02
0

Use GNU Parallel: short, easy to read, and will run one job per core.

for i in *; do inkscape $i --export-png=`echo $i | sed -e 's/svg$/png/'`; done

Know a better way?

If you can do better, submit your command here.

What others think

> might also not be feasible for a large number of files

Yeah, that's a bit of an understatement :-)

If you want to run things in parallel, without your machine grinding to a halt, try xargs -P4

Then you can limit the number of concurrent processes.

Comment by flatcap 58 weeks and 4 days ago

Your point of view

You must be signed in to comment.