Information about change to ImageMagick's "identify" command

I regularly run a script via systemd on a directory which contains pictures I have downloaded to make into wallpapers. The script uses ImageMagick’s identify command to get the dimensions of each image & deletes those which are smaller than my screen’s 1920x1080 resolution. However I just noticed that, even though the script sends me a notification when it is about to run, today my mini-PC’s fan didn’t start while the script was running, which it has always done in the past (but probably not since my last system update).

The script has the following line to identify the dimensions and test if they are smaller than the screen dimension variables “width” & “height”:

identify -format "%[fx:w<${width} || h<${height}]" -- "$file"

So, wondering if something was not right with the script, I ran it manually in a terminal and got the following error on each picture:

identify: GetHslInt failure 0 0,0 @ error/fx.c/ExecuteRPN/3159.
identify: ExecuteRPN failed   @ error/fx.c/FxEvaluateChannelExpression/4022.

It looks like the recent update I did has introduced a change to ImageMagick:

[2024-07-23T17:31:03+1000] [ALPM] upgraded imagemagick (7.1.1.34-1 -> 7.1.1.35-1)

However, a quick Internet search found an easy fix - all I had to do was change:

identify -format

to

magick identify +ping -format

The ImageMagick script now again correctly identifies the dimensions of the pictures & deletes ones that are too small.

The fix was found at:

For those curious about my script to remove .jpg & .png images smaller than my screen, here is the script:

smallpicscurrentdir bash script
#!/bin/bash

# smallpicscurrentdir - a script to remove pictures that have at least
# one side smaller than the set width & height variables 

shopt -s nullglob nocaseglob extglob

width=1920
height=1080

# Just do current directory
for file in *.@(jpg|jpeg|png); do

# Just do subdirectories
#for file in */*.@(jpg|jpeg); do

echo "Checking dimensions of: ${file}"

    a=$(magick identify +ping -format "%[fx:w<${width} || h<${height}]" -- "$file") || continue
    if [[ $a = 1 ]]; then

    rm -v -- "${file}"

      
    fi

done

shopt -u nullglob nocaseglob extglob

exit 0
1 Like

Feedback/Feature Request:

Sometimes the initially rejected images might be desired to be kept for another purpose. A welcome option might be to either move the smaller images to another location, or similarly move the finished/processed images, instead.

The directory is specifically for one purpose on my PC, but anyone is welcome to change the script to suit their own purposes (eg change the rm -v -- "${file}" to mv "${file}" "newfolder/${file}").

The important thing about my post was the change to ImageMagick, not what my script does with it.

Fair enough. It’s also easy enough to just duplicate a directory to keep them separate. Maybe one day you’ll have a huge script archive online, and variations might be useful. :smile:

It does annoy me sometimes when subtle changes as with ImageMagick are made, without any significant or obvious advanced notification. That used to happen a lot with PHP years back.

1 Like