Increase JPEG Quality in WordPress
by Bandicoot Marketing on | Posted in Tutorials | 16 comments
When you upload an image to WordPress it’s processed and compressed to 90% of its original JPEG quality. This is a default setting that’s in place to automatically optimize every image, which in turn can hopefully speed up your site’s loading time.
It’s a nice enough little feature, but the fact that it happens behind the scenes without anyone really knowing it’s going on can cause some users a lot of grief. Especially photographers who see a drop in JPEG quality every time they upload an image.
There’s no option to change this within the WordPress admin and not having the power to control the JPEG quality of your images can be frustrating.
Stop Compressing My Images Already!
As with most features in WordPress, there’s a filter or action in place that we can hook into which will allow us to modify and customize certain functions. For this mod, the filter we need to hook into is called jpeg_quality
.
<?php add_filter( 'jpeg_quality', 'bavotasan_custom_jpeg_quality' ); function bavotasan_custom_jpeg_quality( $quality ) { return 100; } ?>
All the filter requires is a quality setting between 1 and 100, with 100 being no compression whatsoever.
You can read a bit about the jpeg_quality filter and see the original function by checking out the code reference page.
Needs More Compression
If you’re someone who believes in the full extent of optimizing your images, then compressing them even more might be the way to go. It’s an easy enough change since all you need to do is decrease the JPEG quality to a setting below the default of 90.
<?php add_filter( 'jpeg_quality', 'bavotasan_custom_jpeg_quality' ); function bavotasan_custom_jpeg_quality( $quality ) { return 75; } ?>
You can always play around with the number and test out the results. You might discover a perfect balance between smaller file size and optimal image quality.
Make it easier on yourself and install the Regenerate Thumbnails plugin so you don’t have to re-upload your images again and again while trying out different quality settings.
If you have any suggestions or comments, please feel free to use the form below to start a discussion.
Featured image provided by Death to the Stock Photo.
Thanks c.bavota for this post
i have some blogs in blogger also is there any way to increase the quality in blogger also
Not too sure if there is a similar option in Blogger.
Sir, 100 is for no compression and 75 is for 25% compression. I’m right ? This compression is lossless or lossy ? I’m eager to implement this method soon. Thank for useful info 🙂
@Samk No the scale is not a percentage of how much the file will be compressed. The final file size for a giving setting will very much depend on the image and how efficiently it can be compressed. The compression is standard jpeg compression and therefore lossy.
thanks sir
Do you know if the Kraken.io plugin overrule this?
I’m not too sure how that plugin works. It is possible that it does overrule this mod, but I wouldn’t know without trying.
Is there any way to control not just the compression rate of the JPEG encoding but other parameters like the color subsampling as well?
Hmm. Not too sure about that one. I’ve never look further into this in order to do something like that. Check out the codex, though. It is usually pretty informative about stuff like that.
Hi, i want to know if I can config wordpress to compress all types of images, not only jpeg. is it possible?
Must be since there are multiple plugins out there that offer that. Though this might actually work for both JPG and PNG. Have you tested it?
Great post..
I personally use CompressNow tool to reduce image size without losing quality.
Will try out your tutorial soon.
Hi thanks for this awesome article. This is awesome,
May I ask you one thing can we increase size of jpeg image (E.g. A passport size photo is – 10 KB so can we increase its kb like 10 to 20 ?)
Sorry if i asked this question in wrong section, but when I was filling a job form of my friend I got this error, there they need photo of 15-50 KB and my friend’s jpeg pic was only 12 KB.
Thanks.
great article. this will help me a lots in wordpress image compression which will improve page loading time.
thanks 🙂
Getting more knowledge from this post, thanks for shared and I really enjoyed to reading this post regarding to increase of jpeg quality.
I personally use CompressNow tool to reduce image size without losing quality.
Will try out your tutorial soon.