# Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End ImgBrowz0r thumbnail generation

• This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
• Author
Posts
• #29588
sebgonz
Member

Does anyone know how I can change the way that ImgBrowz0r generates thumbnails? I don’t want it to just resize the image to a smaller version of the whole thing, I want it to do what timthumb.php does… how it minimizes it but just shows a portion of the image.

Any help would be appreciated.

#80046
dcp3450
Participant

it’s an algorithm. here is the concept:

you need to know what size you need for either the height or width, find the percentage of the difference, then get the opposite side to match that percentage and create the new height and width. It may be best as an example:

Original Image size
image.png – height: 600px – width: 400px

you want a thumbnail that is 245px high. So you need that image to be:
image.png – height: 245px – width: ?px

Just subtracting the heights and widths won’t work, the picture gets distorted.

The math:

currentHeight = 600;
currentWidth = 400;
newHeight = 245;
newWidth = 0;
sizeDifference = 0;

//get the percentage difference
sizeDifference = (newHeight *100)/currentHeight; //(245*100)/600 = 40.83333..
//get the new width based on the percentage
newWidth = (currentWidth*sizeDifference)/100;//(400*40.83333…)/100=163.3333…
currentHeight = newHeight;
currentWidth = ciel(newWidth);//using ciel() will remove the decimal and round accordingly

image.png – height: 245px – width: 163px

I use this for an artists site to dynamically pull images from the portfolio file and display thumbnails. he can upload any size image he wants and it displays perfect every time.

basic wrap up:

perc_diff = (n1 * 100)/c1;
n2 = (c2 * perc_diff)/100;
c1 = n1;
c2 = ceil(n2);

n: new
c: current
1 & 2: is either height or width depending on what you’re looking for.

Hope this helps!

#80073
dcp3450
Participant

I should note. to use this concept:

//get the percentage difference
sizeDifference = (newHeight *100)/currentHeight; //(245*100)/600 = 40.83333..
//get the new width based on the percentage
newWidth = (currentWidth*sizeDifference)/100;//(400*40.83333…)/100=163.3333…