Skip to content

When creating additional mime types use the original image instead of attached image. #204

Closed

Description

@mitogh

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)
  }
}
  1. Upload the following image

9VQGY3hyMKs

  1. Add the following filter on your site:
		// Use a 1500 threshold
		add_filter(
			'big_image_size_threshold',
			function () {
				return 1500;
			}
		);
  1. And observe the metadata of the image and observe the size 1536x1536 the 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

  1. eclarke1 commented on Mar 4, 2022

    @eclarke1

    @felixarntz @mitogh is this issue ready to be developed against? Or does it need further discussion first? Just trying to clarify next steps please :)

  2. mitogh commented on Mar 4, 2022

    @mitogh
    MemberAuthor

    For the most part this is ready for development @eclarke1 , on thing we need to discuss is how to go about this section:

    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.

    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:

  3. mxbclang commented on Mar 4, 2022

    @mxbclang
    Contributor

    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?

  4. mitogh commented on Mar 4, 2022

    @mitogh
    MemberAuthor

    Agree that makes total sense. @bethanylang, unless @adamsilverstein thinks otherwise.

  5. mxbclang commented on Mar 7, 2022

    @mxbclang
    Contributor

    Thanks @mitogh. I've added #109 for to the list for the next release in #22. @adamsilverstein Let me know if you disagree.

  6. self-assigned this
    on Mar 7, 2022
  7. mitogh commented on Mar 7, 2022

    @mitogh
    MemberAuthor

    Thanks @bethanylang I've cretead a PR for this issue and moved into Review column.

  8. added this to the 1.0.0-beta.2 milestone on Mar 8, 2022
  9. adamsilverstein commented on Apr 5, 2022

    @adamsilverstein
    Member

    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

    @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.

    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions