wand
wand copied to clipboard
Image format incorrect when image instantiated via blob/file-handle
When attempting to determine the format of an Image, it doesn't always come back with the correct image type, depending on how I instantiate the Image object.
Better yet, it also seems to be dependent on OS/versions. When tested on OSX using Python3 and libmagickwand5 it works correctly. However, when tested on Linux using Python3 and ImageMagick-6 it fails consistently.
I've seen this most frequently when trying to detect the format of PDF files, but have also experienced troubles with it when trying to detect the format of a plain text file.
When instantiating the Image object, if I instantiate it as Image(filename=...)
it works correctly. When instantiated as Image(blob=...)
or Image(file=...)
, though, it doesn't always detect the file format correctly.
Here's a sample tests/format_test.py
test suite that exhibits this behaviour:
from wand.image import Image
def test_format_via_filehandle(fx_asset):
with fx_asset.join('sample.pdf').open('rb') as f:
img = Image(file=f)
assert img.format == 'PDF'
def test_format_via_blob(fx_asset):
with fx_asset.join('sample.pdf').open('rb') as f:
buf = f.read()
img = Image(blob=buf)
assert img.format == 'PDF'
def test_format_via_filename(fx_asset):
with Image(filename=str(fx_asset.join('sample.pdf'))) as img:
assert img.format == 'PDF'
I will look into this soon.