尝试将JXR图像转换为JPG格式时,Python Wand的问题和JXR图像的路径?

时间:2015-02-16 12:00:09

标签: python imagemagick imagemagick-convert wand jpeg-xr

我需要能够将JPEG-XR图像转换为JPG格式,并且已经通过ImageMagick本身实现了这一点。但是,我需要能够从python应用程序执行此操作,并一直在使用Wand。 Wand似乎没有正确使用JXR图像的路径。

with open(os.path.join(args.save_location, img_name[0], result[0]+".jxr"), "wb") as output_file:
    output_file.write(result[1])
    with Image(filename=os.path.join(args.save_location, img_name[0], result[0]+".jxr")) as original:
        with original.convert('jpeg') as converted:
            print(converted.format)
            pass

第一部分 - 创建output_file和编写结果[1](来自SQLite数据库的JXR图像的blob) - 工作正常。但是,当我尝试使用Python和Wand将新保存的文件作为图像打开时,我得到一个错误,最终表明Wand没有查找图像的正确位置:

    Extracting panorama 00000
FAILED: -102=pWS->Read(pWS, szSig, sizeof(szSig))
        JXRGlueJxr.c:1806
FAILED: -102=ReadContainer(pID)
        JXRGlueJxr.c:1846
FAILED: -102=pDecoder->Initialize(pDecoder, pStream)
        JXRGlue.c:426
FAILED: -102=pCodecFactory->CreateDecoderFromFile(args.szInputFile, &pDecoder)
        e:\coding\python\sqlite panoramic image extraction tool\jxrlib\jxrencoderdecoder\jxrdecapp.c:477

JPEG XR Decoder Utility
Copyright 2013 Microsoft Corporation - All Rights Reserved

... [it outputs its help page in case of errors; snipped]

The system cannot find the file specified.
Traceback (most recent call last):
  File "E:\Coding\Python\SQLite Panoramic Image Extraction Tool\SQLitePanoramicImageExtractor\trunk\PanoramicImageExtractor.py", line 88, in <module>
    with Image(filename=os.path.join(args.save_location, img_name[0], result[0]+".jxr")) as original:
  File "C:\Python34\lib\site-packages\wand\image.py", line 1991, in __init__
    self.read(filename=filename, resolution=resolution)
  File "C:\Python34\lib\site-packages\wand\image.py", line 2048, in read
    self.raise_exception()
  File "C:\Python34\lib\site-packages\wand\resource.py", line 222, in raise_exception
    raise e
wand.exceptions.BlobError: unable to open image `C:/Users/RPALIW~1/AppData/Local/Temp/magick-14988CnJoJDwMRL4t': No such file or directory @ error/blob.c/OpenBlob/2674

正如你在最后看到的那样,它似乎试图跑开来打开一个临时文件'C:/ Users / RPALIW~1 / AppData / Local / Temp / magick-14988CnJoJDwMRL4'。此时使用的文件名应该与用于将图像保存为上面几行文件的文件名完全相同,但是Wand已经替换了其他内容?这看起来类似于我在ImageMagick中的最后一个问题,这个问题已在周末修复(详见此处:http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=27027&p=119702#p119702)。

有没有人成功获得Wand以在Python中打开JXR图像作为图像,并转换为另一种格式?我在这里做错了什么,或者是ImageMagick或Wand的错误?

1 个答案:

答案 0 :(得分:0)

发生在我身上的事情非常相似。我收到了一个错误:

wand.exceptions.BlobError: unable to open image `/var/tmp/magick-454874W--g1RQEK3H.ppm': No such file or directory @ error/blob.c/OpenBlob/2701

给出的路径不是我要打开的图像的文件路径I.

来自文档:

无法分配,读取或写入二进制大对象。

我正在尝试打开一个大文件。 (18mb.cr)。文件大小可能是问题吗?

对我来说:

from wand.image import Image as WImage

with open(file_name, 'r+') as f:
    with WImage(file = f) as img:
        print 'Opened large image'

或者:

with open(file_name, 'r+') as f:
    image_binary = f.read()

    with WImage(blob = image_binary) as img:
        print 'Opened Large Image'

诀窍

~Victor