Reputation: 1327
I have creating PHP application which takes images with any height and width. It creates 2 different images as follows,
1: thumbnail image (small image) with size 130x130
2: preview image (big image) with 600x400.
How can we decide the height and width of thumbnail & preview image from the height and width of input image?
I have few images with sizes 100x1600, 1024x1024, 316x360.
If i decrease/increase the size of input image most of the time, either any image is streched or compact.
What is the way to find the desired height and width so that thumbnail & preview image looks good?
Upvotes: 1
Views: 534
Reputation:
You need ratio:
$src_ratio = $src_width/$src_height; //ratio of source
$ratio = $width/$height; //ratio of preview
if ($ratio < $src_ratio) $height = $width/$src_ratio;
else $width = $height*$src_ratio+1;
Upvotes: 1
Reputation: 270795
You need the getimagesize()
function.
$attributes = getimagesize($thumbfilename);
var_dump($attributes);
Upvotes: 0
Reputation: 2133
If I understand you correctly, you should use getimagesize() function to get the original size of the image file...
Upvotes: 0