Make WordPress Core

Opened 7 years ago

Closed 6 years ago

#16458 closed defect (bug) (fixed)

image_resize() treats all resized images resulting in JPEG as having the .jpg extension

Reported by: kawauso Owned by: nacin
Milestone: 3.4 Priority: normal
Severity: normal Version: 3.0
Component: Filesystem API Keywords: has-patch commit
Focuses: Cc:


Steps to reproduce:

  1. Upload foobar.jpg
  2. Upload foobar.jpeg
  3. WordPress will use foobar-200x200.jpg and such for the intermediate sizes of the second image

wp_handle_upload() uses image_resize() which attempts to convert all images except GIFs/PNGs to JPEG and hardcodes the .jpg extension. This may well affect all image types handled by GD aside from GIF/PNG when WordPress is given the correct settings to handle them.

The real issue for me is that if the resize procedure fails, it does so silently and just passes back the URL for an existing file matching the output filename.

Attachments (4)

16458.diff (1.2 KB) - added by kurtpayne 7 years ago.
16458.2.diff (706 bytes) - added by SergeyBiryukov 6 years ago.
16458.3.diff (696 bytes) - added by SergeyBiryukov 6 years ago.
16458.4.diff (673 bytes) - added by ryan 6 years ago.
Alternative suggested by nacin

Download all attachments as: .zip

Change History (16)

#1 in reply to: ↑ description @solarissmoke
7 years ago

Related/duplicate #7491

#2 @nacin
7 years ago

  • Version changed from 3.1 to 3.0

Moving version to 3.0 as this would not be a regression.

7 years ago

#3 @kurtpayne
7 years ago

  • Cc kurtpayne added
  • Keywords has-patch added

This patch using an incrementing counter to make the thumbnail filenames unique.

#4 @leogermani
7 years ago

  • Cc leogermani added


I have just stumbled on this problem now... really annoying

Any feedback on this patch or suggestion on how to approach this problem?


#5 follow-up: @SergeyBiryukov
7 years ago

  • Milestone changed from Awaiting Review to 3.4

Perhaps wp_unique_filename() can be used here?

#6 in reply to: ↑ 5 @kawauso
7 years ago

Replying to SergeyBiryukov:

Perhaps wp_unique_filename() can be used here?

Just looked into that. There's a hitch in that it adds to the end of the filename, after the size prefix, so you end up with foobar-200x2002.jpg for a 200x200 resize which can be rather misleading.

#7 @kurtpayne
6 years ago

  • Keywords dev-feedback added

Test case: Upload "uploaded_image.jpg" and "uploaded_image.jpeg"

Default behavior results in:


The resized image names ("....-WIDTHxHEIGHT.jpg") stomp on each other.

With 16458.diff, results are:


The resized image name only gets a counter inserted if the file already exists.

#8 @SergeyBiryukov
6 years ago

Having some issues with 16458.diff on 3.4-alpha-19998, Twenty Eleven, default media settings.

  1. Uploading Untitled.jpg (1000x1000) results in 6 files:

Two of them are the same, so there should be only four. Apparently image_resize() can be called multiple times with the same parameters.

  1. Uploading Untitled.jpeg then results in 4 files:

Three of them overwrite the intermediate sizes of the previous image. This creates orphaned DB records when either image is deleted.

Without the patch, issue 2 still happens, but issue 1 doesn't.

We can probably just preserve .jpeg extension (16458.2.diff).

#9 @nacin
6 years ago

  • Keywords commit added; dev-feedback removed

Fine with 16458.2.diff. Note that if ( 'jpeg' != $ext && 'jpg' != $ext ) $ext = 'jpg'; is going to be quicker than in_array().

Unit tests would be nice.

#10 follow-up: @ryan
6 years ago

Should $orig_type be used here instead of relying solely on the extension?

#11 in reply to: ↑ 10 @ryan
6 years ago

Replying to ryan:

Should $orig_type be used here instead of relying solely on the extension?

I guess not.

6 years ago

Alternative suggested by nacin

#12 @nacin
6 years ago

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

In [20701]:

In image_resize(), do not force the destination filename to *.jpg when we are dealing with a *.jpeg.

props SergeyBiryukov.
fixes #16458.

Note: See TracTickets for help on using tickets.