This is a note to self about how to programmatically resize and crop many images using ImageMagick.
It all started with a folder full of photos with different pixel sizes and ratios. That is because they had been captured with various cameras and had also been manually cropped. This could be verified by running this command to print their pixel sizes:
identify -format "%wx%h\n" *.JPG
Fortunately, all the images had a reasonably large pixel count, so I decided to go for a 5MP pixel count (2560×1920 in 4:3 ratio). That was achieved with this one-liner:
for i in *.JPG; do convert "$i" -resize 3000x1920 -crop 2560x1920+0+0 "$i"; done
The little script looks for all the image files in the folder and starts by resizing them to the preferred height (1920 pixels) and then cropping them to the correct width (2560 pixels). The result is a folder full of equally sized images.
Ps: the script above overwrites the original files in the folder.
I have previously written about how to trim video files with FFmpeg. It is also easy to crop a video file. Here is a short how-to guide for myself and others.
Cropping is not the same as trimming
This may be basic, but I often see the concepts of cropping and trimming used interchangeably. So, to clarify, trimming a video file means making it shorter by removing frames in the beginning and/or end. That is not the same as cropping a video file, which only selects a particular part of the video for export.
If you want to get it done, here is the one-liner:
Sometimes, there is a need to convert an audio file into a blank video file with an audio track. This can be useful if you are on a system that does not have a dedicated audio player but a video player (yes, rare, but I work with odd technologies…). Here is a quick recipe
FFmpeg to the rescue
When it comes to converting from one media format to another, I always turn to FFmpeg. It requires “coding” in the terminal, but usually, it is only necessary to write a oneliner. When it comes to converting an audio file (say in .WAV format) to a blank video file (for example, a .AVI file), this is how I would do it:
ffmpeg -i infile.wav -c copy outfile.avi
The “-c copy” part of this command is to preserve the original audio content. The new black video file will have a copy of the original .WAV file content. If you are okay with compressing the audio, you can instead run this command:
ffmpeg -i infile.wav outfile.avi
Then FFmpeg will (by default) compress the audio using the mp3 algorithm. This may or may not be what you are after, but it will at least create a substantially smaller output file.
Of course, you can easily vary the above conversion. For example, if you want to go from .AIFF to .MP4, you would just do:
My new book will be published Open Access, and I also aim only to use open-source tools as part of the writing process. The most challenging has been to figure out how to make nice-looking illustrations.
Parts of the book are based on the Ph.D. dissertation that I wrote a long time ago. I wrote that on a MacBook and made all the illustrations in OmniGraffle. While it was quite easy to make the switch to Ubuntu in general, OmniGraffle has been one of the few programs I have really missed in the Linux world. True, many graphics tools are available, but none with the same type of finesse as OmniGraffle.
After trying and failing with many of the most popular vector graphics tools, I have ended up using LibreOffice Draw to make all the illustrations. It is more limited than, say, Inkscape but provides the tools I need. It was also easy to get used to the workflow. The only thing I have struggled with figuring out is how to create nice-looking soft drop shadows. In OmniGraffle, the shadow function immediately looks nice, such as in this illustration of how one can think of an instrument as the mediator between action and sound:
My first attempts at adding a shadow in LibreOffice Draw ended up with a gruesome non-soft shadow:
I searched around, but could only find all sorts of complicated solutions. This was last year, and I decided to move on with the project without shadows. I could have moved to another graphics tool but had already spent quite some time making Draw figures. So I decided that shadows were not that important after all.
As part of the final manuscript completion, I am currently making minor changes to all the figures. Out of the blue, I found out that the latest version of Draw now has a more developed shadow section.
Hooray! By changing the “distance,” “glow,” and “transparency” settings, I now finally have soft drop shadows in place:
Draw does still not provide the same smooth user experience as OmniGraffle. But getting the soft drop shadow function in place helps a lot!