Norkin blog

Asmeninis blogas

Archive for the ‘Python’ Category

Python - resize image

with 2 comments

Mazas script’ukas, kuris resizina paveikslelius :]

Naudojam PIL python Image library

import Image, os

# Pradiniai duomenys
imagesDir = "/dir/iki/paveiksleliu/";
width = 100
height = 70

for name in os.listdir(imagesDir):

# Remove thumb's
#	if name.endswith("_thumb.png"):
#		os.remove ( os.path.join(imagesDir, name ) )
	im = Image.open ( os.path.join ( imagesDir, name ) )
	rx, ry = im.size[0]/float(width), im.size[1]/float(height)
	if rx > ry:
		resize = int(width), int ( round ( im.size[1] * ( 1.0 / rx ), 0) )
	else:
		resize = int(round(im.size[0]*(1.0/ry))), int(height)

	im1 = im.resize(resize, Image.BILINEAR )
	im1_name = name[:-4] + '_thumb.png'
	im1.save ( os.path.join ( imagesDir, im1_name ) )

Written by Dummas

May 7th, 2008 at 10:11 am

Posted in Python

Laisvalaikio idėja

without comments

O ką galima parašyti su Python’u?.. Hm.. Na, labai norėčiau parašyti kokį media player’į. Visgi kažkas ’solidesnio’. Bet visi tie unpack, decode, read… Gal tada kokį klient’ą? mpd? Super. Pradedamas developinimas :]

Written by Dummas

May 7th, 2008 at 8:25 am

Posted in Python