fix ox.image

This commit is contained in:
j 2014-10-01 11:05:08 +02:00
parent ab9940425c
commit a04e0ede04
3 changed files with 20 additions and 13 deletions

View file

@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
# GPL 2008
import sys
import re
import string
from six.moves.html_entities import name2codepoint
from six import unichr
from six import unichr, PY2
# Configuration for add_links() function
@ -25,7 +24,7 @@ link_target_attribute_re = re.compile(r'(<a [^>]*?)target=[^\s>]+')
html_gunk_re = re.compile(r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE)
hard_coded_bullets_re = re.compile(r'((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)' % '|'.join([re.escape(x) for x in DOTS]), re.DOTALL)
trailing_empty_content_re = re.compile(r'(?:<p>(?:&nbsp;|\s|<br \/>)*?</p>\s*)+\Z')
if sys.version[0] == 2:
if PY2:
del x # Temporary variable
def escape(html):

View file

@ -3,15 +3,23 @@
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division
from hashlib import sha1
try:
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
except:
import Image
import ImageDraw
import ImageFont
ZONE_INDEX = []
for pixel_index in range(64):
x, y = pixel_index % 8, int(pixel_index / 8)
ZONE_INDEX.append(int(x / 2) + int(y / 4) * 4)
del x
del y
def drawText(image, position, text, font_file, font_size, color):
draw = ImageDraw.Draw(image)
@ -20,7 +28,7 @@ def drawText(image, position, text, font_file, font_size, color):
return draw.textsize(text, font=font)
def getHSL(rgb):
rgb = map(lambda x: x / 255, rgb)
rgb = [x / 255 for x in rgb]
maximum = max(rgb)
minimum = min(rgb)
hsl = [0.0, 0.0, 0.0]
@ -60,7 +68,7 @@ def getImageHash(image_file, mode):
zone_values[ZONE_INDEX[pixel_index]].append(pixel_value)
for zone_index, pixel_values in enumerate(zone_values):
# get the mean for each color channel
mean = map(lambda x: int(round(sum(x) / 8)), zip(*pixel_values))
mean = [int(round(sum(x) / 8)) for x in zip(*pixel_values)]
# store the mean color of each zone as an 8-bit value:
# RRRGGGBB
color_index = sum((
@ -128,7 +136,7 @@ def getRGB(hsl):
rgb[i] = v1 + ((v2 - v1) * 6 * (2/3 - v3))
else:
rgb[i] = v1
return tuple(map(lambda x: int(x * 255), rgb))
return tuple([int(x * 255) for x in rgb])
def getTextSize(image, text, font_file, font_size):
draw = ImageDraw.Draw(image)

View file

@ -1,16 +1,16 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import sys
from ox.utils import json
from six import PY2
from .utils import json
def minify(source, comment=''):
# see https://github.com/douglascrockford/JSMin/blob/master/README
def get_next_non_whitespace_token():
pass
# python2 performance with unicode string is terrible
if sys.version[0] == '2':
if PY2:
if isinstance(source, unicode):
source = source.encode('utf-8')
if isinstance(comment, unicode):