1

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?

1
  • clarify the question.. Do u want to create 2 type of thumbnails keeping aspect ratio? Provide us your syntax and then only we can help you.. we are not magicians.. Commented Jun 7, 2011 at 13:45

3 Answers 3

1

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;
Sign up to request clarification or add additional context in comments.

Comments

0

If I understand you correctly, you should use getimagesize() function to get the original size of the image file...

2 Comments

I have already used it. My question is how can i find out height & width of thumbnail & preview image. I have images with 160x1600, 1024x1024, 316x360 and so on.
according to the task you're creating a app that takes any image and creates thumbs and previews, you should know the sizes, it's impossible to create without knowing the sizes...
0

You need the getimagesize() function.

$attributes = getimagesize($thumbfilename);
var_dump($attributes);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.