Check image width and height before assign the max w and h to the image.