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