Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#20555 closed defect (bug) (fixed)

reserve PNG Format and Transparency for Flexible-Height and Flexible-Width Custom Headers

Reported by: chellycat's profile chellycat Owned by: ryan's profile ryan
Milestone: 3.4 Priority: high
Severity: normal Version: 3.4
Component: Customize Keywords: has-patch
Focuses: Cc:


Normally, when a user uploads a custom header image, they are prompted to crop the image to their desired size if the image is not the exact dimensions specified by the theme. After cropping, the image is compressed and becomes a JPG.

In the past, if users wanted to avoid this compression (to use a transparent PNG for their header image, for example), they could upload their header image at the exact dimensions specified by the theme.

However, with the flexible dimensions, users are always prompted to crop. This means that transparent pngs are converted to JPG and lose their transparency in the process.

To replicate:

  1. Switch to a theme that supports flexible header dimensions (such as Twenty Eleven)
  1. Go to Appearance > Header and upload a transparent png that has the "recommended dimensions" specified by the theme.
  1. You'll be prompted to crop the image.
  1. After cropping, observe how the image becomes a JPG and thus loses its transparency.

The ideal solution would be for PNG images to remain PNGs and to preserve their transparency when cropped.

Attachments (3)

20555.patch (1.5 KB) - added by SergeyBiryukov 12 years ago.
20555.2.patch (2.2 KB) - added by kovshenin 12 years ago.
20555.3.patch (2.7 KB) - added by SergeyBiryukov 12 years ago.

Download all attachments as: .zip

Change History (12)

#1 @nacin
12 years ago

  • Milestone changed from Awaiting Review to 3.4

This is pretty lame. Let's see if there's a way to allow someone to use the original as uploaded (perhaps if there is no crop).

#2 @SergeyBiryukov
12 years ago

  • Keywords has-patch added

We could preserve PNG transparency in wp_crop_image() in the same way image_resize() does.

12 years ago

#4 @kovshenin
12 years ago

  • Cc kovshenin@… added

@SergeyBiryukov your patch works great against latest trunk. Let's also read the image type before creating an attachment post when cropping a header image, otherwise WP thinks it's a jpeg which then breaks Edit Image.

#5 follow-up: @nacin
12 years ago

  • Priority changed from normal to high

I agree with preserving transparency.

Additionally, if $src_x = $src_y = 0, and $src_w = $dst_w, and $src_h = $dst_h, can't we just avoid the crop all together?

#6 @ryan
12 years ago

Related #16458

#7 in reply to: ↑ 5 @SergeyBiryukov
12 years ago

Replying to nacin:

Additionally, if $src_x = $src_y = 0, and $src_w = $dst_w, and $src_h = $dst_h, can't we just avoid the crop all together?

Done in 20555.3.patch.

#8 @ryan
12 years ago

20555.3.patch is working well for me and appears to play nicely with file replication on

If I crop an image to the default crop and upload that image as a new header, it is nigh impossible to get the the exact some crop dimensions again. I could get it to within 1 pixel for x or y. So, I couldn't avoid a crop, but at least it retained png.

#9 @ryan
12 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [20706]:

Don't convert png to jpg when cropping a header. Prevents stomping transparency. Props SergeyBiryukov, kovshenin. fixes #20555

Note: See TracTickets for help on using tickets.