"basename" magic; mass resize images

basename + dirname fun

  • shell> dirname /long/path/file.jpeg
    output: /long/path
  • shell> basename /long/path/file.jpeg
    output: file.jpeg
  • shell> basename /long/path/file.jpeg .jpeg
    output: file
    This one is sooo amazing, ah?!


convert

convert tool comes with ImageMagick. It allows extensive image-manipulation-by-command-line. I've just found out that it supports -resize xx% form, although not mentioned in manpage.

Putting it all together

The 2nd parameter of basename is really useful in mass-filename-scripts. Let's write a script for mass-resizing all jpegs to 50% of their original size:

for i in *.jpeg; do convert -resize 50% $i basename $i .jpeg-resized.jpeg; done


Leave a Reply

Your email address will not be published. Required fields are marked *