Repository navigation
When creating additional mime types use the original image instead of attached image. #204
Description
Bug Description
The current implementation to create images in additional mime types, the image uses the attached image, with get_attached_file when the image is larger a scaled version would be created, however, WordPress creates all the subsizes using the original image instead of the scaled version.
The main problem with the current approach is that in some cases won't create an image of the exact size as the original image, one thing to mention is that the created image on the additional mime types would be of the same aspect ratio, usually, this happens when the scaled version is smaller in dimensions that the created image.
One of the major problems when using the original image is that the resulting WebP images would result bigger in size than the same version in a JPEG, at least specifically with this image and the default quality setting for WebP, this is mostly because the current approach creates a WebP version out of an already compressed version. So would be something to consider either adjust the default WebP from within the plugin to make sure the generated WebP files result in smaller versions of the same JPEG image.
Steps to reproduce
Given the following image subsizes:
> array(6) {
["thumbnail"]=>
array(3) {
["width"]=>
int(150)
["height"]=>
int(150)
["crop"]=>
bool(true)
}
["medium"]=>
array(3) {
["width"]=>
int(300)
["height"]=>
int(300)
["crop"]=>
bool(false)
}
["medium_large"]=>
array(3) {
["width"]=>
int(768)
["height"]=>
int(0)
["crop"]=>
bool(false)
}
["large"]=>
array(3) {
["width"]=>
int(1024)
["height"]=>
int(1024)
["crop"]=>
bool(false)
}
["1536x1536"]=>
array(3) {
["width"]=>
int(1536)
["height"]=>
int(1536)
["crop"]=>
bool(false)
}
["2048x2048"]=>
array(3) {
["width"]=>
int(2048)
["height"]=>
int(2048)
["crop"]=>
bool(false)
}
}- Upload the following image
- Add the following filter on your site:
// Use a 1500 threshold
add_filter(
'big_image_size_threshold',
function () {
return 1500;
}
);- And observe the metadata of the image and observe the size
1536x1536the 2 images have different sizes:
Original JPEG image dimensions are: 1024x1536
Additional WebP dimensions are: 1000x1500
Screenshots
Additional Context
- PHP Version: 7
- OS: Linux 5.15.12-1-MANJARO x86_64
- Browser: Chrome
- Plugin Version:
release/1.0.0-beta.1 - Device: Desktop.

Activity
eclarke1 commentedon Mar 4, 2022
@felixarntz @mitogh is this issue ready to be developed against? Or does it need further discussion first? Just trying to clarify next steps please :)
mitogh commentedon Mar 4, 2022
For the most part this is ready for development @eclarke1 , on thing we need to discuss is how to go about this section:
This can be handled as a secondary issue, but this is very closely related to #109 so we can follow the conversation from that area.
Another related tickets to this work (not a blocker) are:
mxbclang commentedon Mar 4, 2022
Thank you, @mitogh! To clarify, since this issue (#204) is required for the next plugin release, should #109 also be added as a requirement for the next release?
mitogh commentedon Mar 4, 2022
Agree that makes total sense. @bethanylang, unless @adamsilverstein thinks otherwise.
mxbclang commentedon Mar 7, 2022
Thanks @mitogh. I've added #109 for to the list for the next release in #22. @adamsilverstein Let me know if you disagree.
mitogh commentedon Mar 7, 2022
Thanks @bethanylang I've cretead a PR for this issue and moved into Review column.
adamsilverstein commentedon Apr 5, 2022
@mitogh I wasn't able to reproduce this with twentytwetytwo default styles, do you have a code snippet or theme suggestion to add the custom sizes, maybe it is size related? I'm testing the core ticket, so maybe has to do with which image we use as the source.