Recently I have had a couple of emails about changing the amount of compression on TimThumb cropped images. The change itself is really easy, however I thought I would write it up as a reference for those who aren't aware of it's existence.
![]()
To change the level of compression all you have to do is edit the 'q' (which stands for quality) parameter in the query string.
If you don't set the value then a default value of 80 will be used. This generally gives a good trade off between speed and quality, however if you are running a photo site or need to optimize your images for speed, then perhaps you will want to tweak things.
The allowed values are between 0 and 100.
- q=0 is the most compression you can have on the image
- q=100 is the least compression - totally uncompressed
Personally I would never use a quality of 100, it will increase the file size massively for little to no visible gain. If you want to increase the quality then around 95 is the highest you would need to go. The quality level there should be enough for most people.
4 Responses to “TimThumb Quality Settings” Leave a reply ›
I was in this little not aware group of people, so thanks for that
Sometimes it is realy good to write about something that most of us would seen as obvious.
Glad it helped, and you're totally right. There's lots of things I take for granted that I forget others don't know that could help them. I will always try to share these things if I can (if I think of them)
Hi!
I have a problem when resizing images that are smaller than the width/height parameters on the Timthumb request.
The thing is I'm using images from different (*external*) sources, and usually those images are bigger than my width/height and the resizing works perfect, but sometimes they are smaller, and I don't want Timthumb to make them bigger, because then they look pixeled and awful...
I've looked at the code and have tried to modify the MAX_WIDTH and MAX_HEIGHT constants based on new parameters (w2 and h2) but it didn't work (strange)
$max_width = (int) abs (get_request ('w2', 0));
$max_height = (int) abs (get_request ('h2', 0));
if ($max_width > 0) define ('MAX_WIDTH', $max_width);
if ($max_height > 0) define ('MAX_HEIGHT', $max_height);
// ensure size limits can not be abused
$new_width = min ($new_width, MAX_WIDTH);
$new_height = min ($new_height, MAX_HEIGHT);
Thanks for this script, I've been using phpthumb for years and was really tired of it, and today I found it had a security bug (it was ignoring the nohotlinking parameters to allow only certain external webpages and just accepting everything, so dangerous!!!) and found out about Timbthumb, much simpler and effective, great!
Errr actually, that max_width max_height thing was a bit of a nonsense try...
What I want is the image to show at its real size, in the case when its width and/or height is smaller than the width/height parameters, to avoid pixeling at all