PHP thumbnail image
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 i开发者_运维知识库nput 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?
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;
If I understand you correctly, you should use getimagesize() function to get the original size of the image file...
You need the getimagesize()
function.
$attributes = getimagesize($thumbfilename);
var_dump($attributes);
精彩评论