I wanted to resize an image in PHP using the GD library.
I found this question, which helped me alot. It allowed me to do exactly what I wanted. I changed the default value to
instead of the false in the answer, and I also added a way to resize png as well.
function worked splendidly for all the images, until I wanted to scale down this image
to 400x128 (landscape).
This created a black image. I even removed the parts I added on, and used the plain function copied from the question, and it still rendered black. This particular image seems to have trouble with other image sizes such as 400x400 as well. It all works as expected if you disable the crop option.
Is there something wrong with the math included in the function? I tried doing the math on paper replacing variables with the numbers I wanted, but I got confused midway.
for an example. Try changing the values in the second last line to something else. It partially works (not to scale, even though cropping should be to scale).