A Bash Script That I Dream About

Throwing this out there because I know there’s a lot of people on this forum that write scripts and share them with the FOSS community. Maybe there is already a solution to the problem I’m about to describe? I’m sure that I’m not the only one with this issue.

I have been making an effort to post my photos to various websites and social media lately, rather than let them sit idle on my hard drive. When I am done processing, my last step is to resize the pictures for various platforms. For some examples:

  • Instagram is really fussy about aspect ratio in portrait orientation (max is 4:5). If you upload a 2:3 image to Instagram, it will auto-crop it. This means I’m usually resizing the canvas in GIMP and making a new background layer to trick it into a 4:5 ratio.
  • Model Mayhem: Resolution no more than 4 megapixels, and images no more than 1 megabyte in size
  • Flickr: This one is easy - I just upload the highest-res jpg that I have. Flickr will serve smaller files to people but still let them look at the full res version if they want.
  • Personal website: I upload pretty high-res, but compress the pictures more so my website visitors don’t have to download mutiple MB of data if there’s many photos on one page.

There are other sharing services, but these are what I’m familiar with. It would be really nice to have a bash script or something that I could provide a full-resolution TIFF file, and it uses Image Magick or something to output multiple JPG versions of the file with a tag appended to the filename.

Example:
I tell the script to process mybestselfie.tif and it will spit out mybestselfie-web.jpg, mybestselfie-insta.jpg, mybestselfie-flickr.jpg etc., all resized and compressed appropriately. The resolutions, file sizes, etc could be saved in the script itself as variables, so people could easily customize their outputs.

As it is now, even after I finish editing a picture, I have lots more repetitive work to do before I can start posting the pictures. I’m sure it can be automated, and suspect that many people have the same problems I do.

And so long as I’m talking about sharing my photos, feel free to follow my stuff on any of the following:
Instagram: @damonhudacphoto
Flickr: photostream.damonhudacphoto.com
Web: www.damonhudacphoto.com
Facebook: facebook.com/damonhudacphoto

@snibgo is proficient in IM (but he makes scripts for Windows).

Aspect should be relatively simple, although there are nuances that can vex a batch script. For instance, I like to resize my initial processing to 800 pixels on the widest dimension, which differs based on the portrait/landscape orientation as-shot. So, I wrote my command line program to handle resize as follows:

resize:800x600 - resize to those specific x and y dimensions.
resize:800x0 - resize to x=800, y=preserve original aspect ratio
resize:800 - resize to widest=800, so for landscape that’d be x, portrait would be y.

File size is a tougher, in batch to my knowledge you don’t have any feedback on the resulting size until the resize is attempted. I have one website to post that has a size restriction, so I just hardcode a jpeg quality that conservatively meets it.

I cobbled together a tool for this and other tasks:

It works on KDE only, though.

Best,
Dmitri

1 Like

It’s fairly simple to write scripts in any language (bash, Windows BAT, whatever) that does whatever you want in terms of dimensions in pixels, and filesize in bytes. A script mght use ImageMagick or G’MIC or whatever. There may also be other considerations beyond pixels and bytes.

For example, my Snigbo’s ImageMagick pages is about image-processing techniques. Example outputs are typically JPEG for internet speed (both upload and download), so filesize is important but so is fidelity. JPEG compression generally changes the image, and it’s important that this doesn’t obscure the image processing technique I’m trying to demonstrate. So the compression code finds the most aggressive JPEG compression that doesn’t change the image by more than a certain RMSE, usually 1%.

My code for this is written in C. It isn’t published, but that part of the content management system is pretty trivial.

For the common task of resizing photos down, eg for the web, while adding sharpness, I like the technique shown in Resampling with halo minimization. This sharpens without much side-effect such as halos.