Imagemagick cannot read file (MAMP)

I installed the Imagemagick extension on my MAMP dev environment and PHP information in which imagemagick image is installed correctly. However, I get the following exception:

  PHP Fatal error: Uncaught exception 'ImagickException' with message 
 'Unable to read the file:
  /Applications/MAMP/htdocs/image/demo.pdf ' 
 in /Applications/MAMP/htdocs/image/index.php:8
 Stack trace:
 # 0 /Applications/MAMP/htdocs/image/index.php(8): Imagick -> __ construct ('/ Applications / M ...')
 # 1 {main}
   thrown in /Applications/MAMP/htdocs/image/index.php on line 8

Source:

  $ pdf_file = '/Applications/MAMP/htdocs/image/demo.pdf';

 echo $ pdf_file;

 $ save_to = '/Applications/MAMP/htdocs/image/demo.jpg';

 $ img = new imagick ($ pdf_file);

 // reduce the dimensions - scaling will lead to black color in transparent regions
 $ img-> scaleImage (800,0);

 // set new format
 $ img-> setImageFormat ('jpg');

 // save image file
 $ img-> writeImages ($ save_to, false);

Screen short- imagemagick installed on MAMP

Change 1:

I use brew to manage packages.

My MAMP configuration:

Imagick extension (php.ini):

  [imagick]
 extension = "/ usr / local / Cellar / php55-imagick / 3.1.0RC2 / imagick.so"

Envvars:

way:

 /Applications/MAMP/Library/bin/envvars 

Content:

  #if test "x $ DYLD_LIBRARY_PATH"! = "x";  then
 # DYLD_LIBRARY_PATH = "/ Applications / MAMP / Library / lib: $ DYLD_LIBRARY_PATH"
 #else
   #DYLD_LIBRARY_PATH = "/ Applications / MAMP / Library / lib"
 #fi
 #export DYLD_LIBRARY_PATH


 #DYLD_LIBRARY_PATH = "/ Applications / MAMP / bin / ImageMagick / ImageMagick-6.8.9 / lib: / Applications / MAMP / Library / lib: $ DYLD_LIBRARY_PATH"
 #export DYLD_LIBRARY_PATH

+6
source share
2 answers

first check your path to the pdf file:

 if (! is_readable('/Applications/MAMP/htdocs/image/demo.pdf')) { echo 'file not readable'; exit(); } 

if the file is readable, check this out: https://github.com/delphian/drupal-convert-file/wiki/Installing-ImageMagick-on-Mac-OSX-for-PHP-and-MAMP

+4
source

From http://www.php.net/manual/en/imagick.construct.php

when using pdf files, we can indicate which page to use, which may in turn help the correct imageMagick design when using the pdf file

 $pdf_file = '/Applications/MAMP/htdocs/image/demo.pdf'; $img = new Imagick($pdf_file.'[0]'); //[0] indicate the number of the wanted page 
+1
source

Source: https://habr.com/ru/post/971485/


All Articles