从 pdf 转换图像在 php 中不起作用


Converting image from pdf not working in php

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

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

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

您需要删除或转义双引号,它在 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) 将导致 问题。同样,十六进制值中的 # 可能会导致问题,否则 引用。如果在窗口上或使用 变量。否则,单引号或双引号适用于 IM。但如果 您正在从 PHP exec 调用 IM 命令,那么如您所知,您 需要小心(或逃避它们)。