Shortcuts is a Cursed Minefield

This all starts with me wanting to host my photos outside of Instagram. I ended up using GitHub pages and wrote a simple iOS Shortcut to resize and recompress the image to make it suitable for serving on the web.

The shortcut is fairly simple - it takes an image, creates two versions (a main image and a thumbnail for the homepage), crops the thumbnail into a square to fit on the homepage grid, then saves the images to Working Copy ready to be published to GitHub Pages.

The problem arises when cropping the thumbnail. See what I need is:

image showing cropping/resizing

The image needs to be resized to that the shortest side is 600px long, and then crop the centre of that image to a square. Shortcuts has a built-in action for resizing the longest side to a certain length, but not the shortest side.

Instead you have to compare the width and height of the image and resize accordingly:

image showing if statement in shortcuts with resizing

However this gives me stretched out images for landscapes:

squished image after resize

After much head-scratching at what was going on, I figured it out. I was accessing the width and height of the image like this:

accessing height/width with photo media type

While debugging I could print this value and see the correct dimensions for the images that I was selecting. I tried assigning these to separate variables just in case there was some weird type-casting happening when they got passed to the if, but you can’t do less-than or greater-than on arbitrary shortcuts variables:

image showing no less/greater than

In a moment of desperation I swapped the Type to be “Image” rather than “Photo media” (getting desperate at this point), and it worked exactly as it should.

correctly resized and cropped image

Being thorough, I tried changing the Type back to “Photo media”… and it also worked. I made a new shortcut and left it at the default of “Photo media”… and it failed again.

The shortcut would only work if I either left the Type as “Image”, or set it to “Image” and then set it back, obviously flipping some invisible internal value1 of the shortcut to correctly compare the width and height.

No programming language, API, library, or framework has made me as frustrated as writing even the most trivial Shortcuts.

  1. I briefly tried inspecting the internals of the .shortcut file as I have done before, but the signing that is now included made that more difficult than I had enthusiasm for. 

← Create a Mastodon alias using GitHub Pages | The Good & Bad of Photos for MacOS →

Subscribe via RSS or JSON Feed. More posts are in the archive.
Send me a toot on Mastodon: @willhbr@ruby.social.