use pkg_config before have_library

This will fix error with ImageMagick 6.8.0 Q16.