Fix the bug with dark images with new ImageMagick

Backported from v4.7