analitics

Pages

Saturday, July 4, 2009

resize images to create thumbnails

First you have many images.
If you want to create thumbnail for each one this is python script:

import glob 
import PIL
from PIL import Image
for infile in glob.glob("*.jpg"):
 img = Image.open(infile)
 dim_percent=(100/float(img.size[0]))
 dim_size=int((float(img.size[1])*float(dim_percent)))
 img = img.resize((100,dim_size),PIL.Image.ANTIALIAS)
 if infile[0:2] != "trumb_":
  img.save("trumb_" + infile, "JPEG")

Sunday, June 21, 2009

PyGTK and GdkPixbuf

What is GdkPixbuf?
* An object holding information about images in memory.
Constructor
GdkPixbuf (GdkColorspace colorspace, bool has_alpha, int bits_per_sample, int width, int height);

Example:

>>> import pygtk
>>> import pygtk
>>> pixbuf = gtk.gdk.Pixbuf( gtk.gdk.COLORSPACE_RGB, False,8, 200, 100)
>>> pixbuf.save('/home/net/cc/a.jpg','jpeg', {'quality':'100'})

The output is :