now correctly checks image dimensions