URGENT: Image upload & resize issues |
[eluser]BrandonDurham[/eluser]
For some reason the below function fails when the image is only slightly taller than it is wide. I think it's breaking when it gets to the crop bit: Code: function uploadHeaderImage($directory) { Here's the error I get: Quote:The path to the image is not correct Here's a sample image that makes it break: http://www.amillionthingstodo.com/ci/Hys...gogram.JPG If I make that image just 100px wder or taller it works fine. Any ideas? This is kind of urgent. I appreciate any help I can get.
[eluser]err403_love[/eluser]
First, try changing: Code: $config['width'] = 130 * $crop_ratio; to: Code: $config['width'] = floor(130 * $crop_ratio); Because just testing out print_r for a "fake" $config array that I put into its own test file gave me: Code: Array ( [new_image] => fake image path [width] => 937 [height] => 1081.1538461538 [x_axis] => 0 [y_axis] => -8.5769230769231 [maintain_ratio] => ) It SEEMS that Image_lib.php already does this though (rounds), for the width and height. But you should do this at least to troubleshoot and see if it gets rid of your problem. I can't seem to find info on whether or not the X and Y axes need to be an integer, and I can't find anywhere where the Image_lib actually rounds it, so you should definitely try this out, at least to troubleshoot. Also, if you want, try to see if you can use $config['master_dim'] for what you're trying to do. You may be able to get rid of your own ratio code if you use that instead.
[eluser]BrandonDurham[/eluser]
Thanks for the post! Unfortunately the rounding didn't take care of it. The ratio calculations I have here are meant to crop the image from the center (instead of the top left) in the correct dimensions and then resize to 130x150.
[eluser]BrandonDurham[/eluser]
Okay, so I think I figured it out. Because each dimension is not being divided equally (w/130 and h/150) then it's not accurate to say: Code: $crop_ratio = ($img_width >= $img_height) ? $img_height/150 : $img_width/130; SO, I changed it to this and it's now working correctly: Code: $crop_ratio = (($img_width/130) > ($img_height/150)) ? $img_height/150 : $img_width/130;
[eluser]err403_love[/eluser]
Oh.. duh. Sorry. I've done crops exactly like that in other image gallery software, too, so now I feel really stupid for not noticing it. You can remove the floor() from the height/width, too. The Image library does it more accurately by doing it last. Glad you figured it out!
|
Welcome Guest, Not a member yet? Register Sign In |