无法读取文件(MAMP)

时间:2022-02-10 23:54:46

I have installed Imagemagick extension on my MAMP dev environment and PHP info showing imagemagick installed properly. However, I am receiving the following exception:

我已经在MAMP开发环境中安装了Imagemagick扩展,PHP信息显示了正确安装了Imagemagick。但是,我收到以下异常:

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 code:

源代码:

$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);

无法读取文件(MAMP)

Edit 1:

编辑1:

I am using brew for managing packages.

我正在用brew来管理软件包。

My MAMP configuration:

我MAMP配置:

Imagick extension(php.ini):

Imagick扩展(php . ini):

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

Envvars:

Envvars:

path:

路径:

/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

2 个解决方案

#1


4  

first check your pdf filepath:

首先检查您的pdf文件路径:

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

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

如果文件是可读的,请检查:https://github.com/delphian/drupal- convert-file/wiki/installing-imagemagick-on - mac-osx -for php -and- mamp

#2


1  

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

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

apprently when using pdf files, we may specify which page to use, which may in turn help imageMagick construct correctly when using a pdf file

在使用pdf文件时,我们可以指定使用哪个页面,这反过来可以帮助imageMagick在使用pdf文件时正确地构建

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

#1


4  

first check your pdf filepath:

首先检查您的pdf文件路径:

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

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

如果文件是可读的,请检查:https://github.com/delphian/drupal- convert-file/wiki/installing-imagemagick-on - mac-osx -for php -and- mamp

#2


1  

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

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

apprently when using pdf files, we may specify which page to use, which may in turn help imageMagick construct correctly when using a pdf file

在使用pdf文件时,我们可以指定使用哪个页面,这反过来可以帮助imageMagick在使用pdf文件时正确地构建

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