【问题标题】:Converting image from pdf not working in php从pdf转换图像在php中不起作用
【发布时间】:2012-05-28 15:21:40
【问题描述】:

我在我的 C 盘中安装了 ghostscript 和 imagemagick,我在 D 盘中有我的 wamp 服务器,其中一个文件有代码

<?php exec('convert "sd.pdf[0]" -colorspace RGB -geometry 200 "document.png"'); 
?>

文件 sd.pdf 存在于我的程序所在的文件夹中。该程序没有给出错误,但也没有在该文件夹中制作图像。为什么? 附加问题:-在php中使用Imagemagick和ghostscript会使程序变慢还是变快?

【问题讨论】:

  • 在你的shell路径中转换?您的网络服务器用户 ID 在该目录中是否具有写入权限? Ghostscript 是否可以通过网络服务器 ID 执行/访问?
  • 问题只在于双引号

标签: php image-processing imagemagick ghostscript


【解决方案1】:

您需要删除或转义双引号,它在 Windows 上无法正常工作。 查看我的 execute() 方法了解更多信息:https://github.com/webarto/instagraph/blob/master/instagraph.php#L55

public function execute($command)
{
    # remove newlines and convert single quotes to double to prevent errors
    $command = str_replace(array("\n", "'"), array('', '"'), $command);
    # replace multiple spaces with one
    $command = preg_replace('#(\s){2,}#is', ' ', $command);
    # escape shell metacharacters
    $command = escapeshellcmd($command);
    # execute convert program
    exec($command);
}

与 IM 最大的贡献者之一聊天...

没有任何引号, rgb(255, 255, 255) WITH SPACES 将导致 问题。同样,如果不是,十六进制值中的 # 可能会导致问题 引。如果在 Windows 上或使用 多变的。否则,单引号或双引号都适用于 IM。但如果 您正在从 PHP exec 调用 IM 命令,然后如您所知,您 需要小心(或逃避它们)。

【讨论】:

    猜你喜欢
    • 2021-01-14
    • 2011-04-01
    • 1970-01-01
    • 2013-11-27
    • 2018-04-07
    • 2019-01-27
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多