Skip to content

Instantly share code, notes, and snippets.

@ronnyhartenstein
Last active December 7, 2015 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronnyhartenstein/a6a14fa0b5b830ad68d8 to your computer and use it in GitHub Desktop.
Save ronnyhartenstein/a6a14fa0b5b830ad68d8 to your computer and use it in GitHub Desktop.
ImageMagick: find files which can contain spaces (!!) and convert them with xargs instead of -exec -- with bash regexp of the target file
# Inspiration:
# http://www.imagemagick.org/discourse-server/viewtopic.php?t=22974
# http://stackoverflow.com/questions/13043344/search-and-replace-in-bash-using-regular-expressions
# http://www.imagemagick.org/script/command-line-options.php
# stay in target dir
find . -type f -name "*.tif" -print0 | xargs -0 -n1 bash -c 'convert "$0" "${0/.tif/}.jpg"'
# flatten to some other target dir
find . -type f -name "*.tif" -print0 | xargs -0 -n1 bash -c 'convert "$0" jpg/"$(basename "$0" .tif).jpg"'
# with convert CMYK -> RGB (ICC profile here: http://www.adobe.com/digitalimag/adobergb.html)
find . -type f -name "*.tif" -print0 | xargs -0 -n1 bash -c 'echo "$0" "->" "$(basename "$0" .tif).jpg" && convert "$0" -profile "USWebUncoated.icc" -profile "AdobeRGB1998.icc" -quality 75
jpg/"$(basename "$0" .tif).jpg"'
# Windows: correct " - with batch.bat
find . -type f -name "*.tif" -print0 | xargs -0 -n1 bash -c 'echo imconvert \"$0\" -profile USWebUncoated.icc -profile AdobeRGB1998.icc -quality
75 \"jpg/$(basename "$0" .tif).jpg\"' > batch.bat
batch.bat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment