Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image format incorrect when image instantiated via blob/file-handle #195

Open
bleargh45 opened this issue Sep 23, 2014 · 1 comment
Open
Assignees
Labels
upstream-issue Requires a functionality / behavior change outside of this python project

Comments

@bleargh45
Copy link

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'
@dahlia dahlia added the bug label Sep 24, 2014
@dahlia dahlia self-assigned this Sep 24, 2014
@dahlia
Copy link
Collaborator

dahlia commented Sep 24, 2014

I will look into this soon.

@emcconville emcconville added upstream-issue Requires a functionality / behavior change outside of this python project and removed bug labels Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream-issue Requires a functionality / behavior change outside of this python project
Projects
None yet
Development

No branches or pull requests

3 participants