使用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.

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
);