September 11, 2011

How to get image ratio for resize?

PHP: Hypertext Preprocessor

How to get image ratio for resize?

It is an obvious question specially when you have to manipulate an image from small size to large or from large to small. As one of my friend don’t like to invent again a wheel but here we have to understand the manufacturing of a wheel for promising results.

So dudes, suppose you have an image with

width: 1024px

height: 768

And you have to find out the ratio, simply check our the formula from adobe photoshop resizing input fields.

Ratio: w/h

I have improved this formula for more clarity in php function that

pseudo code:





Now, you have to resize an image proportionally. Simply you should know either what width you want for resized image or what height because only one of them is required and the second attribute of resized image will be calculated proportionally.

This post was about how to get image ratio for resize, i will further post regarding resizing formula and php function for resizing an image.

Last updated: March 19, 2014