Post Pic

Prevent WordPress to compress your jpg images

By default, WordPress compress uploaded jpg images. This is a good thing because it makes the files smaller, but in some case, image quality can be more important. If you need to prevent WordPress to compress your images, simply apply this simple tip.

Open your functions.php file and paste the code below in it:

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

Save the file, and you're done. That's simple as that!

Thanks to WP Snippets for the tip!

5 Responses

Mar 30 2012 22:29

Hello
I let you check this page :
http://codex.wordpress.org/Function_Reference/add_filter
The callback can not be a function … Testing before posting is more pro.

Mar 31 2012 01:55

Julio: Reading the full documentation you link to is even more pro; it says, “You can also pass the callback paramater as an anonymous function,” which is what the code given above does.

Mar 31 2012 12:25

Can it work in PHP 5.2.4 (WP min requirements at this time ?)
Because PHP manual says that anonymous functions work only from PHP 5.3.

Apr 01 2012 05:08

Also, this code will only work with PHP 5.3 or newer. WordPress works with older versions, so a disclaimer that this code may cause errors on certain installations may be in order.

Here’s a more compatible snippet:

add_filter( 'jpeg_quality', create_function( '', 'return 100;' ) );

100 can, of course, be changed to any valid percentage. Changing it to 1 results in some interesting, lo-fi uploads.

Apr 02 2012 17:33

Just drop images into ImageOptim instead?

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox