MyBB Community Forums

Full Version: Attachment thumbnail image compression: how to decrease?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
How can I decrease the level of compression MyBB applies when creating attachment thumbnails? Currently they are very jaggy when being resized, and it's creating issues with another plugin I am using that creates large thumbnails.
First, take a backup of this file before editing it => ./mybb/inc/functions_image.php

Second, find following code in "functions_image.php"
	if($width > $maxwidth)
	{
		$newwidth = $maxwidth;
		$newheight = ceil(($height*(($maxwidth*350)/$width))/100);
		$height = $newheight;
		$width = $newwidth;
	}
	if($height > $maxheight)
	{
		$newheight = $maxheight;
		$newwidth = ceil(($width*(($maxheight*350)/$height))/100);

Replace it with

if($width > $maxwidth)
	{
		$newwidth = $maxwidth;
		$newwidth = ceil(($width*(($maxwidth*100)/$width))/100);
		$width = $newwidth;
	}
	if($height > $maxheight)
	{
		$newheight = $maxheight;
		$newheight = ceil(($height*($maxheight*100)/$height))/100);
		$height = $newheight;
		
	}


Now, to increase the size of the thumbnail image, just increase the values here..


Quote:$newwidth = ceil(($width*(($maxwidth*100)/$width))/100);

Change the value colored in red to change the image size by width

and to change the image size by height, change the following value colored in red,
Quote:$newheight = ceil(($height*($maxheight*100)/$height))/100);


Drawbacks:
1 - won't resize already existing thumbnails. => hopefully only one disadvantage
2 - unknown (because I've not tested it on a live site)
I'm not trying to resize them less (though this is useful). I am trying to increase the quality of the thumbnail produced.
I don't understand. Are you talking about the actual attachment? (i.e. when you click the thumbnail and open the image) I haven't noticed any quality loss in my attachments.
I guess Uncontrol needs to make thumbnails with the same quality as of the actual image.. ?
I didn't know MyBB compressed image attachments... Does it really?
Actually when you make a thumbnail out of 900x1000 px image, the image quality must have to reduce as compared to the case where you make a thumbnail out of an 400x400 px image.
The bottom image is the normal image but reduced size. Top image was produced by MyBB attachment compression.

[Image: JdMBU.jpg]

I want it to look more like the bottom image ...
Find all occurences of imagejpeg in inc/functions_image.php and add the optional quality parameter (third parameter, value 100). Or replace it with imagepng for lossless at larger filesize.

However, GD itself in general just does not yield that good a quality. That's why some webapps opt to use some other solution (such as ImageMagick) instead, although that comes with its very own set of issues.
Thank you!
Pages: 1 2