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 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。