Anonymous avatar Anonymous committed fdb5d0a

Pil example

Comments (0)

Files changed (9)

.idea/blogexample.iml

+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>
+

.idea/dictionaries/mikele.xml

+<component name="ProjectDictionaryState">
+  <dictionary name="mikele" />
+</component>

.idea/encodings.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
+</project>
+
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="DependencyValidationManager">
+    <option name="SKIP_IMPORT_STATEMENTS" value="false" />
+  </component>
+  <component name="ProjectResources">
+    <default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
+  </component>
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 2.6.1 virtualenv at ~/Project/mikENV" project-jdk-type="Python SDK" />
+</project>
+

.idea/modules.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/blogexample.iml" filepath="$PROJECT_DIR$/.idea/blogexample.iml" />
+    </modules>
+  </component>
+</project>
+
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="" />
+    <mapping directory="$PROJECT_DIR$" vcs="hg4idea" />
+  </component>
+</project>
+

Python/photoframe.py

+# -*- coding: utf-8 -*-
+
+import os.path
+import sys
+from PIL import Image, ImageFont, ImageDraw, ImageEnhance, ImageOps
+
+WHITEBORDER = 2
+BLACKBORDER = 40
+
+def add_frame(im):
+    """
+    Aggiunge la cornice alla foto
+    """
+
+    img = ImageOps.expand(im, border = BLACKBORDER, fill = 'black')
+    img = ImageOps.expand(img, border = WHITEBORDER, fill = 'white')
+    img = ImageOps.expand(img, border = BLACKBORDER, fill = 'black')
+
+    return img
+
+def file_name_saved(fileroot):
+    """
+    Modifico il nome del file da salvare
+    """
+
+    root, filenamefull = os.path.split(fileroot)
+    filename, extension = os.path.splitext(filenamefull)
+
+    return os.path.join(root, filename + '_framed' + extension)
+
+def main():
+    """
+        sys.argv[1] Path del file da modificare
+        sys.argv[2] Font da utilizzare 
+    """
+
+    if sys.argv > 1:
+        try:
+            img = Image.open(sys.argv[1])
+            font = ImageFont.truetype(sys.argv[2], 80)
+        except IOError:
+            print "Il File non trovato"
+            return
+            
+        newimgwatermark = add_frame(newimgframe)
+        newimgwatermark.save(file_name_saved(sys.argv[1]), "JPEG")
+
+if __name__ == "__main__":
+    main()
+
+
+
+
+

Python/watermark.py

+# -*- coding: utf-8 -*-
+
+import os.path
+import sys
+from PIL import Image, ImageFont, ImageDraw, ImageEnhance, ImageOps
+
+WHITEBORDER = 2
+BLACKBORDER = 40
+
+def add_watermark(im, inputtext, font = None, color = None, opacity = .5):
+    """
+    Aggiunge un watermark alla foto
+    """
+    if im.mode != "RGBA":
+        im = im.convert("RGBA")
+
+    textlayer = Image.new("RGBA", im.size, (0, 0, 0, 0))
+    textdraw = ImageDraw.Draw(textlayer)
+    textsize = textdraw.textsize(inputtext, font = font)
+
+    for y in range(92, im.size[1], 300):
+        for x in range(92, im.size[0], 800):
+            textdraw.text((x , y), inputtext, font = font, fill = color)
+
+    if opacity != 1:
+        alpha = textlayer.split()[3]
+        alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
+        textlayer.putalpha(alpha)
+
+    return Image.composite(textlayer, im, textlayer)
+
+def add_frame(im):
+    """
+    Aggiunge la cornice alla foto
+    """
+
+    img = ImageOps.expand(im, border = BLACKBORDER, fill = 'black')
+    img = ImageOps.expand(img, border = WHITEBORDER, fill = 'white')
+    img = ImageOps.expand(img, border = BLACKBORDER, fill = 'black')
+
+    return img
+
+def file_name_saved(fileroot):
+    """
+    Modifico il nome del file da salvare
+    """
+
+    root, filenamefull = os.path.split(fileroot)
+    filename, extension = os.path.splitext(filenamefull)
+
+    return os.path.join(root, filename + '_watermarked' + extension)
+
+def main():
+    """
+        sys.argv[1] Path del file da modificare
+        sys.argv[2] Font da utilizzare 
+    """
+
+    if sys.argv > 1:
+        try:
+            img = Image.open(sys.argv[1])
+            font = ImageFont.truetype(sys.argv[2], 80)
+        except IOError:
+            print "Il File non trovato"
+            return
+
+        newimgframe = add_watermark(img, sys.argv[3], font, 'white', 0.3)
+        newimgwatermark = add_frame(newimgframe)
+        newimgwatermark.save(file_name_saved(sys.argv[1]), "JPEG")
+
+if __name__ == "__main__":
+    main()
+
+
+
+
+

test.rst

-<
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.