I would expect that $config['maintain_ratio'] = TRUE;
would cause the width to be calculated if I only specify a height. I guess I have to provide any large number for the height to make it work?
$config['image_library'] = 'gd2';
$config['source_image'] = $image_filepath;
$config['new_image'] = $thumbnail_filepath;
$config['maintain_ratio'] = TRUE;
$config['height'] = $this->thumbnail_height;
$this->image_lib->initialize($config);
To create an exact aspect ratio, divide the height by the width. For example: 2:3 aspect ratio: 3 ÷ 2 = 1.5, so you'd drag the slider to 150.
Maintaining aspect ratio is also known as "constraining proportions" in some graphic editing software (like Photoshop). It basically means that the width and height of the resized picture is enlarged/shrunk to proportion, so that the image does not look distorted after it has been resized.
When scaling your image, it's crucial to maintain the ratio of width to height, known as aspect ratio, so it doesn't end up stretched or warped. If you need a specific width and height, you may need a mixture of resizing and cropping to get the desired result.
Correct, you MUST specify both height and width. Since the maintain_ratio option is enabled, the resize will be as close to the target size as possible while preserving the original aspect ratio.
However, if you want to make sure it's always a certain height, set the master_dim config option to 'height', then you can set width to anything and it will always make the resize image that height while maintaining aspect ratio with the width. Similar idea works to maintain width.
@Mitchell McKenna, Thanx. It helped me a lot.
In my project, the source image could have been of any size. and i wanted its width of '245' px, with maintaining ratio, So, I just did like this ....
$config['width'] = '245';
$config['height'] = '1';
$config['maintain_ratio'] = TRUE;
$config['master_dim'] = 'width';
And it worked. Thanx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With