Search code examples
phpubuntuimagemagickexec

PHP exec ImageMagick - magick convert not working ubuntu linux


I'm using ubuntu and have installed ImageMagick

identify -version

gives:

Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib

I tried:

exec('magick img.jpg ( -clone 0 -fill white -colorize 100 ) ( -clone 0 -color-threshold "gray(251)-gray(254)" ) -compose over -composite -quality 80% result.jpg', $output, $return_var);
echo '<pre>' , var_dump($output) , '</pre>';

also convert and magick convert instead of magick

then according to this answer I opened /etc/ImageMagick-6/policy.xml

and changed <policy domain="coder" rights="none" pattern="PDF" /> to <policy domain="coder" rights="read|write" pattern="PDF" />

but still doesn't work and $output always returns empty array

PS: I don't want to use the PHP extension, already did and it has some flaws


Solution

  • Please do some testing in Imagemagick with PHP to see what your versions are. Please provide any messages that come back for each.

    <?php
    echo "<pre>";
    system("type -a convert");  
    echo "</pre>";
    ?> 
    

    <?php
    exec("magick -version",$out,$returnval);
    foreach($out as $text)
    {echo "$text<br>";}
    ?>
    

    Does this work?


    <?php
    exec('magick img.jpg \( -clone 0 -fill white -colorize 100 \) \( -clone 0 -color-threshold "gray(251)-gray(254)" \) -compose over -composite -quality 80% result.jpg 2>&1',$out,$returnval);
    foreach($out as $text)
    {echo "$text<br>";}
    ?>
    

    What messages do you get?