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
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改