trim line endings
moving the Exception to the image resize

We need to check if we can't resize the image before throw a exception.
You'll probably wanna change this.
file_exists() just once on isCached
destroying image created by Imagick
to calc dimensions just if there's no cached file
setting out measures earlier