7290: ImgManip.image_dpi shouldn't return None
always return a sensible default, even if we couldn't read the DPI Use the data from Matthias Basler for ODF docgen code, as that is the only user of image_dpi anyway.
This commit is contained in:
parent
460e631e5b
commit
161ce3b66e
@ -105,33 +105,32 @@ def resize_to_jpeg(source, destination, width, height, crop=None):
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def image_dpi(source):
|
def image_dpi(source):
|
||||||
"""
|
"""
|
||||||
Return the dpi found in the image header. None is returned if no dpi attribute
|
Return the dpi found in the image header. Use a sensible
|
||||||
is available.
|
default of 96.0 dpi for X and Y if N/A.
|
||||||
|
|
||||||
:param source: source image file, in any format that PIL recognizes
|
:param source: source image file, in any format that PIL recognizes
|
||||||
:type source: unicode
|
:type source: unicode
|
||||||
:rtype: int
|
:rtype: int
|
||||||
:returns: the DPI setting in the image header
|
:returns: (x_dpi, y_dpi) from the image header, or defaults to 96 dpi
|
||||||
"""
|
"""
|
||||||
|
dpi = (96.0,96.0) #LibOO 3.6 assumes this if image contains no DPI info
|
||||||
|
# TBD Is this safe for all platforms? See bug# 7290.
|
||||||
try:
|
try:
|
||||||
import PIL.Image
|
import PIL.Image
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import logging
|
import logging
|
||||||
logging.warning(_("WARNING: PIL module not loaded. "
|
logging.warning(_("WARNING: PIL module not loaded. "
|
||||||
"Image cropping in report files will not be available."))
|
"Image cropping in report files will not be available."))
|
||||||
|
|
||||||
dpi = None
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
img = PIL.Image.open(source)
|
img = PIL.Image.open(source)
|
||||||
except IOError:
|
except IOError:
|
||||||
dpi = None
|
pass
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
dpi = img.info["dpi"]
|
dpi = img.info["dpi"]
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
dpi = None
|
pass
|
||||||
|
|
||||||
return dpi
|
return dpi
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -251,11 +250,9 @@ def resize_to_jpeg_buffer(source, size, crop=None):
|
|||||||
img = gtk.gdk.pixbuf_new_from_file(source)
|
img = gtk.gdk.pixbuf_new_from_file(source)
|
||||||
|
|
||||||
if crop:
|
if crop:
|
||||||
# Gramps cropping coorinates are [0, 100], so we need to convert to pixels
|
(start_x, start_y, end_x, end_y
|
||||||
start_x = int((crop[0]/100.0)*img.get_width())
|
) = crop_percentage_to_pixel(
|
||||||
start_y = int((crop[1]/100.0)*img.get_height())
|
img.get_width(), img.get_height(), crop)
|
||||||
end_x = int((crop[2]/100.0)*img.get_width())
|
|
||||||
end_y = int((crop[3]/100.0)*img.get_height())
|
|
||||||
|
|
||||||
img = img.subpixbuf(start_x, start_y, end_x-start_x, end_y-start_y)
|
img = img.subpixbuf(start_x, start_y, end_x-start_x, end_y-start_y)
|
||||||
|
|
||||||
|
@ -1035,8 +1035,6 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
|
|||||||
)
|
)
|
||||||
|
|
||||||
dpi = ImgManip.image_dpi(file_name)
|
dpi = ImgManip.image_dpi(file_name)
|
||||||
if not dpi:
|
|
||||||
dpi = (96.0,96.0) #LibOO 3.6 assumes this if image contains no DPI info
|
|
||||||
|
|
||||||
# ODF wants crop measurements in inch and as margins from each side
|
# ODF wants crop measurements in inch and as margins from each side
|
||||||
left = start_x/dpi[0]
|
left = start_x/dpi[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user