]> Frank Brehm's Git Trees - my-stuff/python.git/commitdiff
Modifications on image resizing
authorFrank Brehm <frank@brehm-online.com>
Sat, 24 May 2014 08:56:48 +0000 (10:56 +0200)
committerFrank Brehm <frank@brehm-online.com>
Sat, 24 May 2014 08:56:48 +0000 (10:56 +0200)
DE-env.py

index ec62371b29bd6f32f7c85ec73e769f8bbd42a000..e86c8e96923f7fdcb5dfda42352848b4e1fd5ffa 100755 (executable)
--- a/DE-env.py
+++ b/DE-env.py
@@ -28,11 +28,14 @@ APP_NAME = 'chwallpaper'
 log = logging.getLogger(APP_NAME)
 verbose = 1
 
-fsize_title = 16
-fsize_subtitle = 11
+fsize_title = 20
+fsize_subtitle = 12
+ssize_title = 2
+ssize_subtitle = 1
 font = '/usr/share/fonts/corefonts/verdanab.ttf'
 if not os.path.exists(font):
     font = '/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf'
+opacity = 0.6
 
 #-------------------------------------------------------------------------
 def init_logging():
@@ -359,6 +362,7 @@ if os.path.exists(wpaper) and os.path.isfile(wpaper):
 
 title = os.path.basename(wpaper)
 title = re.sub(r'\.[^\.]*$', '', title)
+title = re.sub(r'_+', ' ', title)
 new_img_fname = '/tmp/wallpaper.jpg'
 
 old_img = Image(filename = wpaper)
@@ -367,11 +371,20 @@ new_img = old_img.clone()
 screen_height = get_max_monitor_height()
 new_width = int(float(old_img.width) / float(old_img.height) * float(screen_height))
 
-log.debug("Resizing image to %d x %d.", new_width, screen_height)
-new_img.resize(new_width, screen_height)
+log.debug("Old image size: %d x %d.", old_img.width, old_img.height)
 
-black = Color('srgba(0,0,0,0.5)')
-white = Color('srgba(255,255,255,0.5)')
+x_plus = int(float(new_width) * 1.01)
+x_minus = int(float(new_width) * 0.99)
+y_plus = int(float(screen_height) * 1.01)
+y_minus = int(float(screen_height) * 0.99)
+
+if (old_img.width < x_minus or old_img.width > x_plus or
+        old_img.height < y_minus or old_img.height > y_plus):
+    log.debug("Resizing image to %d x %d.", new_width, screen_height)
+    new_img.resize(new_width, screen_height)
+
+black = Color('srgba(0,0,0,%0.1f)' % (opacity))
+white = Color('srgba(255,255,255,%0.1f)' % (opacity))
 
 draw = Drawing()
 
@@ -379,7 +392,7 @@ draw.fill_color = white
 draw.stroke_color = black
 draw.text_antialias = True
 draw.text_alignment = 'center'
-draw.stroke_width = 1
+draw.stroke_width = ssize_title
 draw.text_encoding = 'utf-8'
 draw.font = font
 draw.font_size = fsize_title
@@ -391,6 +404,7 @@ log.debug("Koordinaten: x %r, y %r.", x, y)
 draw.text(x, y, title)
 
 draw.font_size = fsize_subtitle
+draw.stroke_width = ssize_subtitle
 fm = draw.get_font_metrics(new_img, wpaper, False)
 x = int(new_img.width / 2)
 y = int(fm.text_height) + y + 5