forked from josch/img2pdf
only use jp2 to parse jpeg2000 if PIL doesn't support jpeg2000
This commit is contained in:
parent
e5b0ffee6c
commit
c158585618
1 changed files with 11 additions and 4 deletions
|
@ -542,11 +542,17 @@ class pdfdoc(object):
|
||||||
|
|
||||||
|
|
||||||
def get_imgmetadata(imgdata, imgformat, default_dpi, colorspace, rawdata=None):
|
def get_imgmetadata(imgdata, imgformat, default_dpi, colorspace, rawdata=None):
|
||||||
if imgformat == ImageFormat.JPEG2000 and rawdata is not None:
|
if imgformat == ImageFormat.JPEG2000 \
|
||||||
imgwidthpx, imgheightpx, ics = parsejp2(rawdata)
|
and rawdata is not None and imgdata is None:
|
||||||
|
# this codepath gets called if the PIL installation is not able to
|
||||||
|
# handle JPEG2000 files
|
||||||
|
imgwidthpx, imgheightpx, ics, hdpi, vdpi = parsejp2(rawdata)
|
||||||
|
|
||||||
# TODO: read real dpi from input jpeg2000 image
|
if hdpi is None:
|
||||||
ndpi = (default_dpi, default_dpi)
|
hdpi = default_dpi
|
||||||
|
if vdpi is None:
|
||||||
|
vdpi = default_dpi
|
||||||
|
ndpi = (hdpi, vdpi)
|
||||||
else:
|
else:
|
||||||
imgwidthpx, imgheightpx = imgdata.size
|
imgwidthpx, imgheightpx = imgdata.size
|
||||||
|
|
||||||
|
@ -591,6 +597,7 @@ def get_imgmetadata(imgdata, imgformat, default_dpi, colorspace, rawdata=None):
|
||||||
def read_images(rawdata, colorspace, first_frame_only=False):
|
def read_images(rawdata, colorspace, first_frame_only=False):
|
||||||
im = BytesIO(rawdata)
|
im = BytesIO(rawdata)
|
||||||
im.seek(0)
|
im.seek(0)
|
||||||
|
imgdata = None
|
||||||
try:
|
try:
|
||||||
imgdata = Image.open(im)
|
imgdata = Image.open(im)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
|
|
Loading…
Reference in a new issue