[PD] Make a grid for choosing videos. How
august
august at develop.ment.org
Mon Sep 4 17:42:39 CEST 2006
> > ImageMagick provides 'convert':
> >
> > convert -resize 160x120 image.jpg image-thumb.png
> >
> > Note that this preserves aspect ratio, which may or may not be what you
> > want (I haven't worked out how to stretch an image to a precise size
> > with convert yet, if someone knows then please tell me!).
>
> You could also use Python's Image module (PIL) to do thumbnails from
> within Pd, however thumbnails from videos are a different issue, I
> guess.
for video, you could probably use pymedia to produce thumbnails.
http://pymedia.org/
or just use mplayer to render out a frame.
but, just fyi, you will probably want to use imagemagick's convert for
resizing images for thumbnails. It has a few options for it's
resampling algo, but I find the default one to be better than GD's or PIL.
It's also much slower.
below is a python script for converting images. could be easily
modified to use mplayer to render out a frame and resize it using
convert.
-august.
----------------------------------------------------------------
from glob import glob
import os
import Image #PIL
def doConvert(w,h, item, folder, force = False ):
path = folder + "/" + item
# make a folder to hold all the thumbnails
if ( os.path.exists(path) ):
print item + " exists in folder: " + folder
if (force):
print "forcing convert for " + folder + "/" + item
command = "convert " + item + " -resize " + str(w) + 'x' + str(h) + " " + folder + "/" + item
print command
os.system( command )
else:
command = "convert " + item + " -resize " + str(w) + 'x' + str(h) + " " + folder + "/" + item
print command
os.system( command )
def doImage(item, force = False):
image = Image.open(item)
x,y = image.size
msize =648.0 #864
ssize =162.0 #216
mw,mh=10,10
sw,sh=10,10
if (x > y):
sratio = x/ssize
else :
sratio = y/ssize
sw = int( x/sratio )
sh = int( y/sratio )
doConvert(sw,sh,item, "thumbnails", force)
def getList():
return glob("*.jpg") + glob("*.JPG")
# go throught the current directory looking for jpegs and make thumnails
for item in jpglist:
doImage(item, force)
More information about the Pd-list
mailing list