dsw8292301 2014-11-17 07:50
浏览 102

ImageMagick - 将pdf转换为jpg

With this code, I try to convert an uploaded pdf to a jpg.

$newname = date("U");

$target = "../uploads/";
$temp = "../temp/";

if($_FILES["fileToUpload"]["type"] == "application/pdf") {
print "pdf";
if(move_uploaded_file( $_FILES["fileToUpload"]["tmp_name"], $temp.$_FILES['fileToUpload']['name'])) {
    print "pdf saved<br>";
} else {
    print "pdf not saved<br>";
}
$filename = basename( $_FILES['fileToUpload']['name'], ".pdf");
print "<br>".$filename."<br>";
if(file_exists($temp.$_FILES['fileToUpload']['name'])) {
    print "temp-file exist<br>";
    $konv = "/usr/local/bin/convert -debug 'All' ".$temp.$_FILES['fileToUpload']['name']." ".$target.$newname.".jpg 2>&1";
    print $konv."<br>";
    exec("convert -debug 'All' ".$temp.$_FILES['fileToUpload']['name']." ".$target.$newname.".jpg 2>&1", $output); 
    if ($return == "0") { echo "<br>Image generation sucssesful<br>"; } 
    else { echo "<br>Image generation failed<br>"; } 
    print_r($output);
    foreach ( $output as $file ) 
    print "$file<br>";
} else {
    print "temp-file doesn't exist";
}


}

PDF is saved in temp folder, but the image convertion fail and the only error message I get is a 1.

How do I get more informational error messages?

  • 写回答

1条回答 默认 最新

  • doujian1050 2014-11-17 08:12
    关注
    <?php
    $image = new imagick('file.pdf[0]');
    $image->setImageFormat('jpg');
    header('Content-Type: image/jpeg');
    echo $image;
    ?>
    

    Where [0] is the page number.

    pdfinfo will give you the page numbers..

    exec('/path/to/pdfinfo '.$afilename.' | awk \'/Pages/ {print $2}\'', $output);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致