Create watermark and resize images with Python

After holiday, I have many pictures that needs to be uploaded and all of them should have watermark. Watermark in image is one thing that I could’ve done it with photoshop when I was in school. But I’m not gonna waste my time to do that one by one instead I’m doing with this simple python script. The library that I used was PIL (Python Image Library).

This one I’ve done with custom font so you can choose your favorite font in your images. This script will be run two jobs to edit every images you have in one directory. The first thing it gonna resize your image based on what I already defined inside the script, you might want to change the basewidth variable if you want and after resizing, the script will put the watermark at the corner of your image.

For the font, I was just searching for the free license in

Make sure you download the .ttf extension, not sure whether the other extensions will work.

#!/usr/bin/env python
import PIL
from PIL import Image, ImageDraw, ImageFont

def resize():
  image ='IMG_0495.JPG')
  width, height = image.size
  basewidth = 800
  wpercent = (basewidth / float(image.size[0]))
  hsize = int((float(image.size[1]) * float(wpercent)))
  image = image.resize((basewidth, hsize), PIL.Image.ANTIALIAS)'TES.JPG')
def watermark():
  image ='TES.JPG')
  width, height = image.size
  draw = ImageDraw.Draw(image)
  text = "Your credit written here"
  font = ImageFont.truetype('Downloads/Capture_it.ttf', 15)
  textwidth, textheight = draw.textsize(text, font)
  # calculate the x,y coordinates of the text
  margin = 5
  x = width - textwidth - margin
  y = height - textheight - margin
  # draw watermark in the bottom right corner
  draw.text((x, y), text)'TES.JPG')
def main():

Increase sound level in Ubuntu with command line

Sometimes it sucks when you listen to music on youtube with very limited sound level after your volume level has reached maximum and you’re using piece of shit earphone. Just go with this command to extend the limitation sound level, it works on ubuntu 14.04:

$ pactl -- set-sink-volume 0 150%

be careful with maximum sounds, can be dangerous for your ears.

Make paging output from your python script

pydoc is a python library to make your console output paginates for easier reading. to use it follow the simple example below:

import pydoc

text = "...paginate me..."
pager = pydoc.ttypager(text)
print pager

you will see the output is gonna be truncated at the beginning when you start to see like when you open up a man page, then you have to scroll down with keyboard to read the rest of the text line by line. pretty cool!