duanhuo7441 2017-03-09 15:15
浏览 68
已采纳

使用Imagick裁剪除了底部10%的图像以外的所有图像

I am reading an 8.5 x 11" PDF and creating a jpg thumbnail.

I want to crop all but approx the bottom 10% of the image. (basically only want the footer in the final)

$pdf_file   = $file;
$save_to = 'bottom.jpg';
$img = new imagick();
$img->setResolution(300,300);
$img->readImage("{$pdf_file}[0]");
$img->scaleImage(800,0);
$img->setImageFormat('jpg');
$img = $img->flattenImages();
$img->cropImage(0,0,0,350);
$img->writeImages($save_to, false);

echo '<img src="bottom.jpg">';

The output of the above code produces a jpg showing the footer, however the image is 800px W X 685px H with white space on top of the footer.

I just want the footer at 800px W X approx 200px H.

  • 写回答

1条回答 默认 最新

  • dongzhun1857 2017-03-09 16:21
    关注

    I'm not sure why you're passing in zero 3 times to the crop function. The parameters are meant to be:

    • width - The width of the crop
    • height - The height of the crop
    • x - The X coordinate of the cropped region's top left corner
    • y - The Y coordinate of the cropped region's top left corner

    So this should do what you want:

    $img->cropImage(
        $image->getImageWidth(),
        350, 
        0,
        $image->getImageHeight() - 350
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 flask项目,怎么使用AJAX传数据库数据到echarts图表的data里,实现异步加载数据。
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?