Tuesday, April 28, 2009

Make things smaller

To make the images for a GUI recently, I used gimp to do a screen capture of a Google maps picture of the earth (under File... Acquire). But the images I made at first made the GUI too big, so I needed to make them all 1/2 their linear dimension.

1. Use mkdir -p small/big to create small and its subdirectory big in one swell foop.

2. Copy some big images into small/big.

3. cd into small/big. You can iterate over the files like this:

for f in *.jpg ; do echo File $f: ; ls -l $f ; echo and thats all for file $f. ; done

You can also format it more nicely, and bash will let you know when you're inside the loop by giving a > prompt instead of the normal one:

for f in *.jpg
echo File $f
ls -l $f

4. You can use convert, part of the ImageMagick package, to convert an image from one type to another and to scale it (and to do many, many other things like cropping and overlaying text):

convert foo.jpg -scale '90%' smaller-foo.png

Challenge: use a for loop to convert each of the images in small/big into an image with the same name in small/.

Extra credit: Use seq to create a for loop that prints out the even numbers from 4 to 20, using sleep to pause 1/4 second between each number. Hint: you'll need to use backticks: ` around the call to seq. Explain in detail what the backticks do for double extra credit.

No comments:

Post a Comment