How can I run ImageMagick from a shell_command?

I have installed ImageMagick (7.1.1-32) on my HASS (Core2024.9.1) via:

[core-ssh config] apk add --update imagemagick

In my config.yaml, I have this:

shell_command:
  conv_jpg_pnp: magick /config/www/myImage.jpg /config/www/myImage.png

When I try to run that shell_command via Developer Tools | Actions I get this:

stdout: ""
stderr: "/bin/sh: magick: not found"
returncode: 127

However, running the same command from the SSH Terminal addon or an SSH terminal from a remote PC the magick executable works as expected.
As I understand it, the shell_command is executed in the /config folder?
From this point, where is the magick executable? Do I include this full path to magick in my config.yaml?

Regards, Martin

1 Like

The problem is that the imagemagick has to run within the Home Assistant Core container, instead of the ssh container. The other problem is when you update HA Core, the installed imagemagick is deleted and has to be re-installed.

To install imagemagick in HA Core including after an update, here is what I do:
create a shell command file (I named mine add_imagemagick.sh) under config/shell_commands that contains the following:

#!/bin/bash

if ! test -f "/usr/bin/convert"; then
    apk add imagemagick
fi

Note: technically you could instead test for the presence of the file /usr/bin/magick instead of /usr/bin/convert as convert is now just a symbolic link to the real file magick.

Create the shell command in your yaml config:

shell_command:
  imagemagick_add: /config/shell_commands/add_imagemagick.sh

Create an automation that runs at homeassistant startup time

action:
  - data: {}
    action: shell_command.imagemagick_add

At this point you should be able to run your conf_jpg_pnp shell command.

Thank you Tommy,
Apologies for not acknowledging sooner. :frowning_face:
Suffice to say that your example is working flawlessly.
Regards, M.