Sublime directory Surf the web anonymous Pagerank Monitor


Suggestion for small change to Foto_upload class code

CoreyLoose
Sun 12 November 2006, 12:37 am GMT +0100
I have been doing some work with photo uploading and resizing using Easy PHP Upload. It has preformed exaclty as needed but I have made one modification to the source and thought I should share it with the community.

The check_dimensions function within the Foto_upload class  uses a simple $x_check < $y_check to decide which side of the image should be sized down to its max setting. If an image is 1000px wide and 950px tall with max settings of 100 x 100 this works fine. It sees the image is wider than tall and sizes it down to 100px wide and 95 px tall.

The issue I have run into is that if you are working with max x and y values that are not equal this logic fails. The settings I am using are x_max at 100 and y_max at 60. If if a image happens to be 1000px wide and 950px tall, like before, the function still resizes the image to 100 x 95 leaving the y value above the set max.

The solution I am using is to choose which side to scale down to the max based on proportion:
if( $this->x_max_thumb_size / $this->x_size > $this->y_max_thumb_size / $this->y_size ){
//y stuff
}else{
//x stuff
}
So instead of whichever side is bigger it chooses whichever side has a greater gap from it's max setting

What do you think? Is this a better way to go about it?
~Corey

olaf
Sun 12 November 2006, 10:04 am GMT +0100
Thanks Corey I will check that.

Archive for SMF v1.00 by N.P. Valid XHTML 1.0 Transitional