I’ve actually used this command before but today I was pleasantly surprised. I had used it in the past to change from one image format to another. It’s actually very straight forward and it helps a bunch when you just want an easy way to convert images. You can change the extensions of the files to signify what type of image you want to convert to.
convert in.jpg out.png
Today I wanted to do something a bit different. I wanted to rapidly re-size a bunch of images I had in a directory. As with the last case I wanted to avoid opening up gimp and manually changing all the images. I know that you can do it in gimp with python and other scripting languages, but it seems overkill for me. I revisited the `convert` command and it gave me the solution that I was searching.
convert in.jpg -resize GEOMETRY out.jpg
GEOMETRY in this case can be a lot of things. I used two flavors of this argument. You can either define the height and width of the image or the percentage of resizing. If you want to define the height and the width you use ‘x’ to separate the two values:
convert in.jpg -resize 40x40 out.jpg
This is cool if you know exactly what dimensions you want out of your resulting image. In my case I just wanted the image to shrink by a certain ratio. This is where the command surprised me :). One can also define the GEOMETRY as a percentage. when the percentage is more than 100, it means that the image is going to increase in size. If the percentage is 100, then the image will not be re-sized (I think it’s not touched). Finally, when the percentage is less than 100, the image shrinks. I used the command in the following manner:
convert in.jpg -resize 30% out.jpg
This is really convenient for me because I can just use a shell `for` to traverse all my images:
for file in *; do convert $file -resize 30% smaller-$file; done ;