ImageMagik not converting/processing images

Been trying to get to the bottom fo this one for hours, including talking to my host for ideas. For some reason images are just passed through and not actually getting processed by Imagemagik. WebP generation results in a woops error, saying:

The imagemagick convert command could not be executed

AVIF files seem to be just being passed through (and Jpeg t i think). Ive confirmed this with a HexEditor. Also used the greyscale thumb option with the jpg images which come through as color.

My host confirms that exec() is allowed and functioning, and their Sys Admin ran the same convert command that kirby is trying manually on the command line which worked fine.

Everything works fine locally where i am using ImageMagick 7.1.1-41 Q16-HDRI aarch64 but not on the server which is is running ImageMagick 6.9.10-68 Q16 x86_64.

I have even tried the starterkit to rule out my project, and i get the same results there.

I have no idea what else to try. Using PHP 8.3.6 and Kirby 4.6.1.

What if you run the exec command with the convert command from a simple PHP script outside of Kirby?

Yes, that works…I just scaled down a jpg succefully via a litle php script. soo things get weirder then :frowning:

And you have added the correct path to the convert binary in your config?

Yes, that is set correctly.

  'thumbs' => [
    'driver' => 'im',
    'bin' => '/bin/convert'

  ],

Thats the path i get when i run which convert on the server, confirmed as correct by the hosts SysAdmin.

My hosts SysAdmin used the following script to check if exec works

<!DOCTYPE html>
<html>
<head>
    <title>exec() Test</title>
</head>
<body>
    <h2>Testing exec() in PHP</h2>
    <?php
    // Check if exec is enabled
    $execEnabled = function_exists('exec') && !in_array('exec', array_map('trim', explode(',', ini_get('disable_functions'))));

    if ($execEnabled) {
        echo "<p><strong>exec() is enabled.</strong></p>";
        
        // Run a test command
        $output = [];
        $return_var = 0;
        exec('whoami', $output, $return_var);

        echo "<p>Command Output:</p><pre>" . implode("\n", $output) . "</pre>";
        echo "<p>Return Status: $return_var</p>";
    } else {
        echo "<p><strong>exec() is disabled.</strong></p>";
    }
    ?>
</body>
</html>

That all checks out when i run it.

I tweaked the exec() line earlier to scale down a jpeg which worked.

At a bit of a loss now why Kirby throws an error when trying run convert.

What exactly are you running in your Kirby code to get these thumbs? Would be interesting if it is anything special in that exact convert command that fails.

Nothing crazy I dont think…

<picture class="feature">
    <source src="<?= $image->thumb(['width' => 570, 'crop' => true, 'format' => 'avif',])->url() ?>" type="image/avif">
    <source src="<?= $image->thumb(['width' => 570, 'crop' => true, 'format' => 'webp'])->url() ?>" type="image/webp">
    <img src="<?= $image->thumb(['width' => 570, 'crop' => true, 'format' => 'jpg'])->url() ?>" alt="<?= $image->alt() ?>">
</picture>

I also ran the more invovled example in the thumbs docs, which also failed:

<img src="<?= $image->thumb(
    [
        'width'     => 300,
        'height'    => 300,
        'crop'      => 'center',
        'format'    => 'webp',
        'grayscale' => true,
        'blur'      => 300,
        'sharpen'   => 50,
        'quality'   => 70,
    ]
)->url() ?>" alt="">

The source image is a Jpeg or PNG set in a files field.

when i tested the starter kit, i replaced the images on the home page with the picture tag above, and same thing happened.

Ok, the second one creates the following convert command, which is then passed to exec().

'/opt/homebrew/bin/convert' -limit thread '1' '/Users/xxx/sites/4xz/media/pages/about/506c85d86e-1738856755/table-300x300-crop-blur300-bw-q70-sharpen50.webp' -colorspace gray -auto-orient -thumbnail '300x300^' -gravity 'Center' -crop '300x300+0+0' -quality '70' -blur '0x300' -sharpen '0x0.5' '/Users/xxx/sites/4xz/media/pages/about/506c85d86e-1738856755/table-300x300-crop-blur300-bw-q70-sharpen50.webp'

Maybe you can try this with some image and adapted paths in your test script

Running the following manipulating a webp file to a smaller webp with the blur and sharpen etc does not work, and the return var gets set to 1 in result. There is nothing in the output var (not sure there should be). If i run the same script but using a jpeg as input, it works as expected , i get the output.jpg generated, and the return var remains at 0.

<!DOCTYPE html>
<html>
<head>
    <title>exec() Test</title>
</head>
<body>
    <h2>Testing exec() in PHP</h2>
    <?php
    // Check if exec is enabled
    $execEnabled = function_exists('exec') && !in_array('exec', array_map('trim', explode(',', ini_get('disable_functions'))));

    if ($execEnabled) {
        echo "<p><strong>exec() is enabled.</strong></p>";
        
        // Run a test command
        $output = [];
        $return_var = 0;
        exec("'/bin/convert' -limit thread '1' '/home/XXX/input.jpg' -colorspace gray -auto-orient -thumbnail '300x300^' -gravity 'Center' -crop '300x300+0+0' -quality '70' -blur '0x300' -sharpen '0x0.5' '/home/XXX/output.jpg'", $output, $return_var);

        echo "<p>Command Output:</p><pre>" . implode("\n", $output) . "</pre>";
        echo "<p>Return Status: $return_var</p>";
    } else {
        echo "<p><strong>exec() is disabled.</strong></p>";
    }
    ?>
</body>
</html>

i am guessing an error of some kind was generated, since the return var got changed but i didnt get any feedback in the script and there is nothing in the error log.

It sounds a bit like the imagemagick version does not support webp and probably avif.

It’s unfortunately exactly that specific imagemagick version that seems to have a problem: Webp conversion broken with ImageMagick 6.9.10-68 Q16 x86_64 2019-10-07 and PHP Plugin - Legacy ImageMagick Discussions Archive

Oh thats great, thanks @bastianallgeier

I have reported this to my host, so hopefully they will upgrade both GD and IM for me since i discovered issues with AVIF/WebP and GD as well (the installed GD doesnt like newer versions of PHP).

1 Like

So once again stellar support from Krystal Hosting - it turns out that having been a customer of theres for a long time, the version of linux powering my re-seller hosting is the oldest they have in their fleet. I’m told it is already on their internal roadmap for an upgrade “In the nex few months”. Fourtunatly they have offered to expedite my upgrade, which is briliant because I really cannot wait as long as that.

The SysAdmin even created a test cPanel account on the newer platform so that i could go in and mess around to see that it does what i need it to, which was super nice of them.

There is a reason i swear by this host :slight_smile:

I guess i can mark this as solved now since the ball is with my host to resolve it.

1 Like

I share the experience with their support. They are really nice.

1 Like

Everything sorted now, server migration took less then 10 minutes from me saying go ahead… now thats :rocket: :rocket: :rocket: !!