]> Frank Brehm's Git Trees - my-stuff/python.git/commitdiff
Added image mangling
authorFrank Brehm <frank@brehm-online.com>
Sun, 18 May 2014 12:34:44 +0000 (14:34 +0200)
committerFrank Brehm <frank@brehm-online.com>
Sun, 18 May 2014 12:34:44 +0000 (14:34 +0200)
DE-env.py

index f4ca499605854e616061f5dc69134d6781af5eb9..1a6d6c334d6069161005f4c553ce09f565f2c3b4 100755 (executable)
--- a/DE-env.py
+++ b/DE-env.py
@@ -17,8 +17,16 @@ import re
 import random
 from gi.repository import Gio
 
+from wand.image import Image
+from wand.color import Color
+from wand.drawing import Drawing
+
 APP_NAME = 'bluberblubb'
 
+fsize_title = 16
+fsize_subtitle = 11
+font = '/usr/share/fonts/corefonts/verdanab.ttf'
+
 def get_desktop_environment():
     #From http://stackoverflow.com/questions/2035657/what-is-my-current-desktop-environment
     # and http://ubuntuforums.org/showthread.php?t=652320
@@ -225,8 +233,8 @@ def get_home_dir():
         raise KeyError("Neither USERPROFILE or HOME environment variables set.")
 
 bg_dirs = [
-    '/home/fbrehm/Bilder/Wallpaper',
-    '/home/frank/Bilder/bg',
+    #'/home/fbrehm/Bilder/Wallpaper',
+    '/home/frank/Bilder',
     '/usr/share/backgrounds',
 ]
 
@@ -259,7 +267,48 @@ cur_wpaper = gsettings.get_string(KEY)
 
 print("Current Wallpaper: %r." % (cur_wpaper))
 print("Setting Wallpaper to: %r." % (wpaper))
-#if os.path.exists(wpaper) and os.path.isfile(wpaper):
-#    gsettings.set_string(KEY, wpaper)
+if os.path.exists(wpaper) and os.path.isfile(wpaper):
+    gsettings.set_string(KEY, wpaper)
+
+title = os.path.basename(wpaper)
+title = re.sub(r'\.[^\.]*$', '', title)
+new_img_fname = '/tmp/wallpaper.jpg'
+
+old_img = Image(filename = wpaper)
+new_img = old_img.clone()
+
+black = Color('srgba(0,0,0,0.5)')
+white = Color('srgba(255,255,255,0.5)')
+
+draw = Drawing()
+
+draw.fill_color = white
+draw.stroke_color = black
+draw.text_antialias = True
+draw.text_alignment = 'center'
+draw.stroke_width = 1
+draw.text_encoding = 'utf-8'
+draw.font = font
+draw.font_size = fsize_title
+
+fm = draw.get_font_metrics(new_img, title, False)
+x = int(new_img.width / 2)
+y = int(fm.text_height)
+#print("Koordinaten: x %r, y %r." % (x, y))
+draw.text(x, y, title)
+
+draw.font_size = fsize_subtitle
+fm = draw.get_font_metrics(new_img, wpaper, False)
+x = int(new_img.width / 2)
+y = int(fm.text_height) + y + 5
+#print("Koordinaten: x %r, y %r." % (x, y))
+draw.text(x, y, wpaper)
+
+draw(new_img)
+
+new_img.save(filename = new_img_fname)
+
+
+
 
 # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4