converting multiple files
converting multiple PNG files to PNG files with a width of 400 pixels
for i in !(*-small.png) ; do if test ! -s "${i%.*}-small.png" ; then convert "$i" -resize '400' "${i%.*}-small.png" ; fi ; done
converting multiple TIFF files to PNG files
In the current directory, each file with the .tiff
file extension not already accompanied by a file with .png
in place of .tiff
or -intermediate.png
in place of .tiff
will be converted into two PNG files.
for i in *.tiff ; do if { test ! -s "${i%.*}-intermediate.png" && test ! -s "${i%.*}.png"; } ; then convert "$i" "${i%.*}-intermediate.png" && pngcrush "${i%.*}-intermediate.png" "${i%.*}.png" ; fi ; done
explanation
Note
This is an incomplete explanation.
*-small.png
uses the asterisk (*
) special character for filename expansion, matching every filename ending in-small.png
.- The
-resize '400'
option changes the image geometry to a width of 400 pixels.
prior work
- The
test
command was introduced to me by a comment on a question I asked on Stack Overflow by fmw42. - The bulk of the contents of the script's for-loop construct was introduced to me by an answer on Super User by Kevin Cox.
- The bulk of the contents of the script's if-construct was introduced to me by the test (Unix)§Examples page on Wikipedia.
- The correct syntax for the if-contruct was introduced to me by an answer on Stack Overflow by Shawn Chin.
licensing
Some rights reserved: CC BY-SA 3.0. Includes significant content from an answer on Super User by Kevin Cox and test (Unix)§Examples on Wikipedia, with changes made.