Avoid Windows path prefix for ImageMagick

This commit is contained in:
Adrian Sampson 2016-06-06 10:21:30 -07:00
parent bfa56b1d8d
commit a9573cea0c
2 changed files with 14 additions and 4 deletions

View file

@ -124,15 +124,23 @@ def check_art_similarity(log, item, imagepath, compare_threshold):
is_windows = platform.system() == "Windows"
# Converting images to grayscale tends to minimize the weight
# of colors in the diff score.
# of colors in the diff score. So we first convert both images
# to grayscale and then pipe them into the `compare` command.
# On Windows, ImageMagick doesn't support the magic \\?\ prefix
# on paths, so we pass `prefix=False` to `syspath`.
convert_cmd = [b'convert', syspath(imagepath, prefix=False),
syspath(art, prefix=False),
b'-colorspace', b'gray', b'MIFF:-']
compare_cmd = [b'compare', b'-metric', b'PHASH', b'-', b'null:']
log.debug(u'comparing images with pipeline {} | {}',
convert_cmd, compare_cmd)
convert_proc = subprocess.Popen(
[b'convert', syspath(imagepath), syspath(art),
b'-colorspace', b'gray', b'MIFF:-'],
convert_cmd,
stdout=subprocess.PIPE,
close_fds=not is_windows,
)
compare_proc = subprocess.Popen(
[b'compare', b'-metric', b'PHASH', b'-', b'null:'],
compare_cmd,
stdin=convert_proc.stdout,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,

View file

@ -10,6 +10,8 @@ Some fixes for Windows:
* Queries are now detected as paths when they contain backslashes (in
addition to forward slashes). This only applies on Windows.
* :doc:`/plugins/embedart`: Image similarity comparison with ImageMagick
should now work on Windows.
Fixes: