- This topic is empty.
-
AuthorPosts
-
July 9, 2010 at 2:52 pm #29588sebgonzMember
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.
July 19, 2010 at 11:29 pm #80046dcp3450Participantit’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: 400pxyou want a thumbnail that is 245px high. So you need that image to be:
image.png – height: 245px – width: ?pxJust 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…
//set your sizes
currentHeight = newHeight;
currentWidth = ciel(newWidth);//using ciel() will remove the decimal and round accordinglyyour new image size is:
image.png – height: 245px – width: 163pxI 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!
July 20, 2010 at 8:36 am #80073dcp3450ParticipantI 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…
//set your sizes
currentHeight = newHeight;
currentWidth = ciel(newWidth);//using ciel() will remove the decimal and round accordinglyecho it as such:
echo ‘<img src="/images/image.png" height="’.$currentHeight.’" width="’.$currentWidth.’" alt="">’; -
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.