Welcome Guest, Not a member yet? Register   Sign In
Resize and maintain the golden ratio (3:5)?
#1

[eluser]markanderson993[/eluser]
Hello there CodeIgniter experts! I was wondering if there was a way to crop a picture to a 3:5 ratio?

I hope this question was simple!

Thanks in advance for any help! Smile

- Pianoman993
#2

[eluser]TheFuzzy0ne[/eluser]
Code:
function getWidth($height)
{
    return ($height / 3) * 5
}

Supply the height you want to the function and you'll get the right width back.
#3

[eluser]markanderson993[/eluser]
Thanks for the reply.

What if the picture was say 728px by 800px, would this still be able to crop the photo down to a 3:5 dimension? And if the photo was wider than tall it would appear 3 high and 5 long? (and vice-versa)
#4

[eluser]TheFuzzy0ne[/eluser]
The longest dimension should be used as your master dimension.

If the height is the largest dimension:
Code:
function getWidth($height)
{
    return ($height / 3) * 5
}

If the width is the largest dimension:

Code:
function getHeight($width)
{
    return ($width / 5) * 3
}

Just bear in mind that the further the image is away from this ratio, the more image you'll lose when it's cropped.
#5

[eluser]markanderson993[/eluser]
Makes sense to me. Thanks for your help Fuzzy!
#6

[eluser]TheFuzzy0ne[/eluser]
Sorry, I was wrong. You'd need to crop by the smallest dimension. It's 5:32AM and my brain is not working any more.

Code:
function getCropDimensions($width, $height)
{
    if ($height < width) // Height is master dim
    {
        $width = ($height / 3) * 5;
    }
    else // Otherwise width is master dim
    {
        $height = ($width / 5) * 3;
    }
    return array(
            'height' => $height,
            'width' => $width
        );
}
The above code is untested, but should work for you.




Theme © iAndrew 2016 - Forum software by © MyBB