beyondcode / herd-community

82 stars 1 forks source link

Convert function not available? #234

Closed psntr closed 11 months ago

psntr commented 11 months ago

Operating system version

macOS Sonoma 14.1

System architecture

ARM64 (M1, M2, etc)

Herd Version

1.3.1

PHP Version

PHP 8.2

Bug description

Despite having imagick extension provided by Herd, I'm not able to use the 'convert' command through php.

I tried to install imagick.so with Pecl, but it's conflicting with the one that is already installed with Herd.

does anyone face the same issues?

Steps to reproduce

No response

Relevant log output

No response

crazywhalecc commented 11 months ago

Could you provide the specific code to reproduce the following?

psntr commented 11 months ago

Sure this is the code:

$output = null;
        $retval = null;
        if(function_exists('exec')) {
            echo "exec is enabled<br>";
        }
        exec('which convert', $output, $retval);

        if ($retval === 0) {
            echo $binPath = $output[0];  // Path to 'convert'
        } else {
            echo "'convert' is not found";
        }
    The code above works on my web server, which output the binary path.
crazywhalecc commented 11 months ago

The convert command is a tool provided by the imagemagick library after compilation. PHP's imagick extension provides the function of calling imagemagick methods within PHP, and does not include imagemagick's own command line tool.

If you are going to use the convert command, perhaps compiling the imagemagick project separately is a better option.

psntr commented 11 months ago

I see, that makes sense, however, compelling the imagemagick requires me to install via pecl as recommended by the documentation here.

crazywhalecc commented 11 months ago

The imagemagick library and imagick extension can be treated as two completely different things. If you don't need to use the PHP methods mentioned in PHP Imagick Documentation and just want to use convert command, you can just call imagemagick directly through exec, and there is no need to install the imagick extension.

psntr commented 11 months ago

I think the CMS I'm using which is Kirby CMS, use the command convert, so I wanted to make sure that locally I set the convert's path correctly. As seen in their doc

crazywhalecc commented 11 months ago

It seems that Kirby CMS only uses the convert command, and it should be enough to install imagemagick directly using Homebrew.

psntr commented 11 months ago

Thank you, if that's the case, I have it already installed via Homebrew. But still I'm not able to use properly convert, it seems like this path doesn't work. 'bin' => '/opt/homebrew/bin/convert', do I have to edit my .zhrsc file to add a specific alias?

psntr commented 11 months ago

Sorry, never mind, it's now properly converting my image. Thanks for your help!

edit: typo

alancwoo commented 1 month ago

Sorry, never mind, it's not properly converting my image. Thanks for your help!

Did you mean it's now properly converting...? Did you manage to solve it? As I'm having the same issue with Kirby with Laravel Herd.

psntr commented 1 month ago

Yeah, sorry for the typo, indeed, it's now working on my side, I was also having issue since I have the repo of my app on two separate computers, one running with the Apple Silicon new chips and one running with the Intel which used to be here: /usr/local/bin/convert.

Now both of my computers run on Apple Silicon, and so the correct path after installing imagemagick via Homebrew is:/opt/homebrew/bin/convert which is a symlink created by Homebrew for the original path which is /opt/homebrew/Cellar/imagemagick/7.1.1-21/bin/convert.

So make sure that your that you have either one or the other symlinks by running: ls -l /opt/homebrew/bin/convert if on Apple Silicon or : ls -l /usr/local/bin/convert if on Intel.

You can also try to hash -r to refresh the shell cache.

alancwoo commented 1 month ago

Ah thanks for the response! Actually it seems one should just define the path to convert in the config: https://getkirby.com/docs/reference/system/options/thumbs#thumbs-driver__additional-options-for-the-imagemagick-driver

psntr commented 1 month ago

Oh yes! I should have mentioned it earlier, but I was having issue with Kirby not properly using the library despite having the path defined in the config, but turned out I was using the wrong path and was mixing up between legacy path and the new one from the symlink… Well I hope it's working for you now