orangelabweb / imagemagick-engine

WordPress plugin to replace image engine with ImageMagick.
https://wordpress.org/plugins/imagemagick-engine/
9 stars 9 forks source link

ime_im_cli_check_executable($fullpath) always returns false #29

Closed miro-ux closed 2 years ago

miro-ux commented 2 years ago

I couldn't set the engine to cli. imagemagick is installed and convert is working via SSH. image

The problem seems to be that !@is_executable($fullpath) returns false even thought convert is set to 777.

Commenting out the check seems to fix the issue and it works/resizes as expected: Edit : Commenting out the check passes the test button but upon saving it revers to PHP module.

        //always returns false
    if (!@is_executable($fullpath)) { 
        //return false; 
    }

image

Is this just me? Can you reproduce?

Ubuntu: 18.04.6 PHP: 7.2.24 ImageMagick: 6.9.7-4

rickardw commented 2 years ago

What do you get if you run "which convert" on your server via SSH?

miro-ux commented 2 years ago

What do you get if you run "which convert" on your server via SSH?

/usr/bin/convert

rickardw commented 2 years ago

And can you confirm that your web server allows PHP to run executables?

miro-ux commented 2 years ago

Yes. Here's a simple test on the same server and domain i'm testing the plugin on.

In fact, I was able to get it to work and save the CLI mode by commenting both is_executable checks.

/*
 * ImageMagick executable handling
 */

// Do we have a valid ImageMagick executable set?
function ime_im_cli_valid() {
    $cmd = ime_im_cli_command();
    return !empty($cmd); //&& @is_executable($cmd);
}

// Test if we are allowed to exec executable!
function ime_im_cli_check_executable($fullpath) {
    if (!@is_executable($fullpath)) {
        //return false; 
    }
    @exec( "$fullpath --version", $output );

        ime_set_option( 'imagemagick_version', $output, true );

    return (is_array($output)) ? (count( $output ) > 0) : false;
}

My humble guess is that is_executable checks for something else that exec isn't influenced by. I have no idea why...

miro-ux commented 2 years ago

Found this answer. It's is a good alternative to is_executable which works without issues for me.

Here's the final code:

/*
 * ImageMagick executable handling
 */

// Do we have a valid ImageMagick executable set?
function ime_im_cli_valid() {
    $cmd = ime_im_cli_command();
    return !empty($cmd) && `which $cmd`;
}

// Test if we are allowed to exec executable!
function ime_im_cli_check_executable($fullpath) {
        if (!`which $fullpath`) {
        return false; 
    }
    @exec( "$fullpath --version", $output );

        ime_set_option( 'imagemagick_version', $output, true );

    return (is_array($output)) ? (count( $output ) > 0) : false;
}
rickardw commented 2 years ago

Thank you, will be implemented in next release

https://github.com/orangelabweb/imagemagick-engine/commit/c5ff73718a5db21253c070330b5597c81715350e