WordPress.org

Forums

WP Resized Image Quality
[resolved] Does 100% mean, there is no compression? (7 posts)

  1. Robnonstop
    Member
    Posted 1 year ago #

    Just to be certain, does a 100% setting have the same effect as adding

    add_filter('jpeg_quality', function($arg){return 100;});
    add_filter( 'wp_editor_set_quality', function($arg){return 100;} );

    to the Theme’s function.php? Or is there a difference?

    Is the file re-saved or passed on the way it is? I’m asking because even at a maximum quality setting, a JPEG will degrade with each saving.

    Thank you!

    http://wordpress.org/plugins/wp-resized-image-quality/

  2. Mike Bijon
    Member
    Plugin Author

    Posted 1 year ago #

    Hey @Robononstop, your code example is exactly correct. RIQ just sets the value passed to the JPEG quality filters.

    And the 100% quality options are re-saved. That's the default a big negative to how WordPress handles JPEGs.

    Good idea to skip the save though. We'd have to unhook the re-save, and I've added an issue to the plugin's repo for doing just that: https://github.com/mbijon/WP-Resized-Image-Quality/issues/1

  3. Mike Bijon
    Member
    Plugin Author

    Posted 1 year ago #

    There isn't currently a way to stop WordPress from compressing JPEGs at the "100%" level.

    Based on the instances of this '$quality' variable, the compression always happens: http://phpxref.ftwr.co.uk/wordpress/_variables/index.html#quality

    It would be nice to see WP either skip the compression if quality is 100%, or to have an added hook that would let us detect & skip the re-save action based on $quality.

  4. Marko Heijnen
    Member
    Posted 1 year ago #

    Not sure what you mean but 100% is the highest quality WordPress can pass. It will mean that GD you a higher quality. Maybe with Imagick it can be wrong for JPG and I will check that next week

  5. Mike Bijon
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Marko, I'll try to explain 100% JPEG compression better:

    * All JPEG images are run through a process that breaks them up into squares of pixels (8x8, 16x16, varies based on quality) and then uses an algorithm to convert each set of pixels from pixel/spatial data into transform/frequency data.

    * Converting from pixels to transform info discards some info. Even at 100% quality info is discarded.

    Then...

    * Each time a JPEG is re-saved, even at 100%, it's treated as pixel data & re-converted to a transform block-by-block. Thus, more info is discarded each time a 100% JPEG is re-saved.

    So, 100% isn't just the best quality that WordPress can generate, it's the highest that the JPEG format can manage. And each time something is saved at 100% it gets worse. That's the concern here.

    As for PNG, WordPress doesn't currently have any code in core for compressing PNGs. There are some libraries that handle PNG compression if you want to install them on your server. I discussed them in this support thread last year: http://wordpress.org/support/topic/png-optimisation?replies=13

  6. Marko Heijnen
    Member
    Posted 1 year ago #

    I wrote a part of the code behind WP_Image_Editor so I do know how compression works. You blamed WordPress on the compression and not JPEG itself. Thats why I commented.

    Also WordPress can handle changing the quality of PNGs but only when you are using Imagick. With GD there is a ticket for that but it's not in yet.

  7. Mike Bijon
    Member
    Plugin Author

    Posted 1 year ago #

    Gotcha. Thanks for building what's there. Guess I should read more of the Imagick detection code. I could probably wrap that to detect & maybe-enable PNG compression in RIQ.

    I tend to generalize in answers on these forums. No blame on WordPress ... just easier & faster than being 100% complete & specific.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Resized Image Quality
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic