Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/atoidejouer/tools/image.py
diff options
context:
space:
mode:
Diffstat (limited to 'atoidejouer/tools/image.py')
-rw-r--r--atoidejouer/tools/image.py43
1 files changed, 22 insertions, 21 deletions
diff --git a/atoidejouer/tools/image.py b/atoidejouer/tools/image.py
index c3c9288..f5ff573 100644
--- a/atoidejouer/tools/image.py
+++ b/atoidejouer/tools/image.py
@@ -42,7 +42,6 @@ def get_pixbuf(file_path, max_width, max_height, use_max=False):
def get_sequence_first_graphic(type_, sequence_name, size=None):
- # ..
_filename = storage.get_sequence_first_graphic_name(type_, sequence_name)
if _filename is None:
_path = storage.get_image_path('blank', dir_='data')
@@ -57,7 +56,6 @@ def get_sequence_first_graphic(type_, sequence_name, size=None):
size = (64, 48)
else:
pass
- # ..
return get_pixbuf(_path, *size)
@@ -65,6 +63,8 @@ def compute_width_height(width, height, max_width, max_height, use_max=False):
# compute ratio
_ratio_scr = max_width / float(max_height)
_ratio_img = width / float(height)
+ # DEBUG
+ logger.debug('[tools.image] compute_width_height - r_src/r_img: %s/%s' % (_ratio_scr, _ratio_img))
# ..
if width > max_width\
or height > max_height:
@@ -77,7 +77,9 @@ def compute_width_height(width, height, max_width, max_height, use_max=False):
else:
width = max_width
height = max_height
- # ..
+ # DEBUG
+ logger.debug('[tools.image] compute_width_height - w/h: %s/%s' % (width, height))
+ logger.debug('[tools.image] compute_width_height - max_w/max_h: %s/%s' % (max_width, max_height))
return width, height
# ..
elif use_max is True:
@@ -87,7 +89,7 @@ def compute_width_height(width, height, max_width, max_height, use_max=False):
return width, height
-def get_image_info(path):
+def get_image_info(path=None, data=None):
"""Tricky method found on Internet that returns the image info from a given
raw image data.
"""
@@ -96,51 +98,50 @@ def get_image_info(path):
# already exist
if _info is not None:
return _info
- elif os.path.exists(path):
+ elif data is not None:
pass
+ elif os.path.exists(path):
+ # read file
+ _f = open(path)
+ data = _f.read()
+ _f.close()
else:
return None, 0, 0
-
- # read file
- _f = open(path)
- _data = _f.read()
- _f.close()
#
- size = len(_data)
+ size = len(data)
height = 0
width = 0
content_type = None
-
# handle GIFs
- if (size >= 10) and _data[:6] in ('GIF87a', 'GIF89a'):
+ if (size >= 10) and data[:6] in ('GIF87a', 'GIF89a'):
# Check to see if content_type is correct
content_type = 'image/gif'
- w, h = struct.unpack("<HH", _data[6:10])
+ w, h = struct.unpack("<HH", data[6:10])
width = int(w)
height = int(h)
# See PNG 2. Edition spec (http://www.w3.org/TR/PNG/)
# Bytes 0-7 are below, 4-byte chunk length, then 'IHDR'
# and finally the 4-byte width, height
- elif ((size >= 24) and _data.startswith('\211PNG\r\n\032\n')
- and (_data[12:16] == 'IHDR')):
+ elif ((size >= 24) and data.startswith('\211PNG\r\n\032\n')
+ and (data[12:16] == 'IHDR')):
content_type = 'image/png'
- w, h = struct.unpack(">LL", _data[16:24])
+ w, h = struct.unpack(">LL", data[16:24])
width = int(w)
height = int(h)
# Maybe this is for an older PNG version.
- elif (size >= 16) and _data.startswith('\211PNG\r\n\032\n'):
+ elif (size >= 16) and data.startswith('\211PNG\r\n\032\n'):
# Check to see if we have the right content type
content_type = 'image/png'
- w, h = struct.unpack(">LL", _data[8:16])
+ w, h = struct.unpack(">LL", data[8:16])
width = int(w)
height = int(h)
# handle JPEGs
- elif (size >= 2) and _data.startswith('\377\330'):
+ elif (size >= 2) and data.startswith('\377\330'):
content_type = 'image/jpeg'
- jpeg = StringIO.StringIO(_data)
+ jpeg = StringIO.StringIO(data)
jpeg.read(2)
b = jpeg.read(1)
try: