7290: image_dpi default calc based on gtk.gdk
This commit is contained in:
parent
161ce3b66e
commit
36f84e1d0d
@ -103,18 +103,17 @@ def resize_to_jpeg(source, destination, width, height, crop=None):
|
|||||||
# image_dpi
|
# image_dpi
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
INCH_PER_MM = 1/25.4
|
||||||
def image_dpi(source):
|
def image_dpi(source):
|
||||||
"""
|
"""
|
||||||
Return the dpi found in the image header. Use a sensible
|
Return the dpi found in the image header. Use a sensible
|
||||||
default of 96.0 dpi for X and Y if N/A.
|
default of the screen DPI or 96.0 dpi 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: (x_dpi, y_dpi) from the image header, or defaults to 96 dpi
|
:returns: (x_dpi, y_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:
|
||||||
@ -129,8 +128,19 @@ def image_dpi(source):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
dpi = img.info["dpi"]
|
dpi = img.info["dpi"]
|
||||||
|
return dpi
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
import gtk
|
||||||
|
dpi = (
|
||||||
|
gtk.gdk.screen_width() / (INCH_PER_MM * gtk.gdk.screen_width_mm()),
|
||||||
|
gtk.gdk.screen_height() / (INCH_PER_MM * gtk.gdk.screen_height_mm())
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
dpi = (96.0,96.0) #LibOO 3.6 assumes this if image contains no DPI info
|
||||||
|
# This isn't safe even within a single platform (Windows), but we
|
||||||
|
# can't do better if all of the above failed. See bug# 7290.
|
||||||
return dpi
|
return dpi
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user