Welcome Guest, Not a member yet? Register   Sign In
Image cropping challenge
#11

[eluser]Shahgeb[/eluser]
I am just telling my opinion on its ration of image issues. if iamge is in rectangle form than it can convert it into and size just pick width and calcute its height using this formula width*3/4 . than output height will b same and as orginal height with ration of 4:3 where 4 is width and 3 height
#12

[eluser]Shahgeb[/eluser]
any comment and suggestion appreciated on my comments
thanks
#13

[eluser]KeyStroke[/eluser]
Thank you so much Colin. You've pushed me in the right direction.

Now that I'm over converting aspect ratio, I've figured out the rest. Building on your code:

Code:
$ratio_x = 240;
$ratio_y = 145;
list($image_x, $image_y) = getimagesize($image_filepath);

$new_image_y = $image_y;
$new_image_x = $image_x;

if ($ratio_x > $ratio_y)
{
   $new_image_y = ($image_x * $ratio_y) / $ratio_x;
}
else
{
   $new_image_x = ($image_y * $ratio_x) / $ratio_y;
}

$crop_x = ($image_x - $new_image_x) / 2;
$crop_y = ($image_y - $new_image_y) / 2;

And it works like a charm!

And regarding your warning, I don't think the new dimensions could be larger than the original. (Correct me if I'm wrong)




Theme © iAndrew 2016 - Forum software by © MyBB