Thursday, 27 January 2011

python image cropping ( crop )

import Image
a = Image.open('screenshot-20110127@110832.png')
b = a.crop((100, 100, 400, 400)) # left, top, right, bottom.
b.save('output.png')

or, say,

import os, Image
a = os.listdir(os.getcwd())
# List of paired elements: [[image, filename], [image, filename], ...]
b = [[Image.open(i), i] for i in a if 'screenshot' in i]
c = [[i[0].crop((400, 312, 1410, 950)), i[1]] for i in b] # crop
[i[0].save(i[1][:-3] + 'new.png') for i in c] # save with new filenames.

Friday, 21 January 2011

ramdisk

from linux screw.

mkdir /tmp/ramdisk; chmod 777 /tmp/ramdisk
sudo mount -t tmpfs -o size=2048M tmpfs /tmp/ramdisk

or, use /dev/shm

even easier.