Long ago I created a small library for resizing images using imagemagick through system(...) because I did not feel that the build-in imagemagick functions for PHP
I tell one suggestion you can try it,
I saw the Image link I think the conditions are not checked correctly.
you have checked condition [(width/height) > (maxWidth/maxHeight)] Instead of check
if(width == height) { } elseif(width > height) { } else(width < height){ }
Check this condition and according to this condition crop the image and resize.
Thank you