Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#45598 closed enhancement (fixed)

Prevent unnecessary whitespace around thumbnails when processing cropped PDFs

Reported by: michelweimerskirch's profile michel.weimerskirch Owned by: joemcgill's profile joemcgill
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch commit
Focuses: Cc:

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 5 years ago.
Patch
demo_cropped.pdf (61.9 KB) - added by michel.weimerskirch 5 years ago.
Demo file to reproduce the issue
demo-before-patch.png (126.6 KB) - added by michel.weimerskirch 5 years 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 5 years ago.
Thumbnail generated AFTER the patch

Download all attachments as: .zip

Change History (11)

@michel.weimerskirch
5 years ago

Demo file to reproduce the issue

@michel.weimerskirch
5 years ago

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

@michel.weimerskirch
5 years ago

Thumbnail generated AFTER the patch

#1 in reply to: ↑ description @michel.weimerskirch
5 years 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
5 years ago

  • Description modified (diff)

#3 @joemcgill
5 years 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.


5 years ago

#5 @joemcgill
5 years 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.


5 years ago

#7 @kirasong
5 years 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.