douhoushou8385 2014-09-24 08:41
浏览 64

将pdf转换为jpg,将jpeg转换为缩略图

I have written code for converting pdf to jpeg and its working fine but what option should I pass to create thumbnail in the exec();(for width and height purpose). here I am getting. I have tried -dDEVICEWIDTHPOINTS=100 -dDEVICEHEIGHTPOINTS=200 option but it seems invalid arguments.

following is my code:

 //include 'thumbcreator.php';
 ini_set('display_errors', 1);
 $pdf='example.pdf';
 $quality=90;
 $res='300x300';
 $exportName="pdf_export_" . time();
 $exportPath=realpath(dirname(__FILE__))."/$exportName/fullres/%03d.jpg";
 $exportPaththumb=realpath(dirname(__FILE__))."/$exportName/fullresthumb/%03d.jpg";

 mkdir(realpath(dirname(__FILE__))."/$exportName");
 mkdir(realpath(dirname(__FILE__))."/$exportName/fullres");
 mkdir(realpath(dirname(__FILE__))."/$exportName/fullresthumb");
 set_time_limit(900);
 exec("'gs' '-dNOPAUSE' '-sDEVICE=jpeg' '-dUseCIEColor' '-dTextAlphaBits=4' '-dGraphicsAlphaBits=4' '-o$exportPath' '-r$res' '-dJPEGQ=$quality' '$pdf'",$output);
 exec("'gs' '-dNOPAUSE' '-sDEVICE=jpeg' '-dUseCIEColor' '-dTextAlphaBits=4' '-dGraphicsAlphaBits=4','-dDEVICEWIDTHPOINTS=100 -dDEVICEHEIGHTPOINTS=200' '-o$exportPaththumb' '-r$res' '-dJPEGQ=$quality' '$pdf'",$output);

 for($i=0;$i<count($output);$i++){
             echo($output[$i] .'<br/>');
 }

Any help will be appreciated. Thanks in advance :).

  • 写回答

1条回答 默认 最新

  • dsf8897 2014-09-24 09:02
    关注

    Why do you think DEVICEWIDTHPOINTS and DEVICEHEIGHTPOINTS are invalid arguments ?

    You haven't set -dFIXEDMEDIA so the initial values can be overriden by media requests from the input. You probably will also want to set -dPDFFitPage in order to scale the PDF input to fit on the declared media size, if you don't do that, then you'll just get the bottom left corner of the input rendered.

    Don't set -r when using this, the resolution will have to be recalculated in order to scale the input into the fixed size media you have requested. (Note that you have requested the media in points, 1/72 inch)

    Please don't use -dUSECIEColor, that's a horrible hack from the PostScript world. Unless you know precisely what you are doing, that will result in worse colour management.

    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本