WordPress.org

Make WordPress Core

Opened 11 months ago

Closed 2 months ago

#45598 closed enhancement (fixed)

Prevent unnecessary whitespace around thumbnails when processing cropped PDFs

Reported by: michel.weimerskirch Owned by: joemcgill
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch commit
Focuses: Cc:
PR Number:

Description (last modified by SergeyBiryukov)

When generating thumbnails from cropped PDF pages, Imagemagick uses the uncropped area - resulting in unnecessary (and ugly) whitespace - unless the option "use-cropbox" is set.

I attached a patch that solves the issue by setting a parameter in ImageMagick. Note that this doesn't in any way affect uncropped PDFs.

I also attached a demo.pdf for you to reproduce the issue as well as two thumbnails generated before and after the patch.

Attachments (4)

wp-imagemagick-pdf-thumbnail.patch (1.1 KB) - added by michel.weimerskirch 11 months ago.
Patch
demo_cropped.pdf (61.9 KB) - added by michel.weimerskirch 11 months ago.
Demo file to reproduce the issue
demo-before-patch.png (126.6 KB) - added by michel.weimerskirch 11 months ago.
Thumbnail generated BEFORE the patch (with whitespace around the cropped image not visible in the PDF itself)
demo-after-patch.png (118.8 KB) - added by michel.weimerskirch 11 months ago.
Thumbnail generated AFTER the patch

Download all attachments as: .zip

Change History (11)

@michel.weimerskirch
11 months ago

Demo file to reproduce the issue

@michel.weimerskirch
11 months ago

Thumbnail generated BEFORE the patch (with whitespace around the cropped image not visible in the PDF itself)

@michel.weimerskirch
11 months ago

Thumbnail generated AFTER the patch

#1 in reply to: ↑ description @michel.weimerskirch
11 months ago

Replying to michel.weimerskirch:

Not that this doesn't in any way affect uncropped PDFs.

Small typo. This should say "Note that this doesn't in any way affect uncropped PDFs." (unfortunately, Trac doesn't allow editing tickets)

#2 @SergeyBiryukov
11 months ago

  • Description modified (diff)

#3 @joemcgill
7 months ago

  • Keywords needs-testing added
  • Milestone changed from Awaiting Review to 5.3
  • Owner set to joemcgill
  • Status changed from new to accepted

Thanks @michelweimerskirch, this looks like a nice improvement. I'm adding this to the 5.3 milestone for testing.

This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.


4 months ago

#5 @joemcgill
4 months ago

  • Keywords commit added; needs-testing removed

Patch applies cleanly and works great without introducing any noticeable performance problems (in fact, if can improve performance because Imagick is generating smaller images).

Also wanted to reiterate that this change will only affect PDFs that have been created with a tool that includes a crop-box. For more info about the CropBox setting, I found this article helpful: https://www.w3pedia.com/uk/the-pdf-page-boxes-cropbox-bleedbox-trimbox.

This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.


4 months ago

#7 @mikeschroder
2 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 46238:

Media: Prevent unnecessary whitespace around PDF Thumbnails.

Stops unintended whitespace from showing around PDF thumbnails
when the PDF creation tool utilized a CropBox.

Props michelweimerskirch, joemcgill.
Fixes #45598.

Note: See TracTickets for help on using tickets.