ein bildbearbeitungsscript und ein sound normalisierungsteil
hintugefuegt
This commit is contained in:
parent
5cdf4e88e8
commit
3e013a1c9b
2 changed files with 226 additions and 0 deletions
142
spielspass/gallery.py
Executable file
142
spielspass/gallery.py
Executable file
|
@ -0,0 +1,142 @@
|
|||
#!/usr/bin/env python
|
||||
# see: http://www.amk.ca/python/code/
|
||||
|
||||
import sys, os, getopt
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError:
|
||||
print >>sys.stderr, ("Unable to import PIL.Image; "
|
||||
"is the Python Imaging Library installed?")
|
||||
sys.exit(0)
|
||||
|
||||
__version__ = '1.01'
|
||||
__doc__ = """%s [option] file1 file2
|
||||
Options:
|
||||
--help Display this usage message
|
||||
--html Output HTML to stdout
|
||||
--resize x y Resize specified images to x,y
|
||||
--rotate x Rotate the image counter clockwise for x degrees
|
||||
--size Display the image sizes
|
||||
--thumbnail x y Make thumbnails of specified images, ignoring existing
|
||||
thumbnails that happen to be listed among the files.
|
||||
|
||||
If a filename is of the form *_thumb.*, it's assumed to be a thumbnail.
|
||||
|
||||
""" % sys.argv[0]
|
||||
|
||||
def is_thumbnail (filename):
|
||||
"Returns true if the filename is for a thumbnail"
|
||||
root, ext = os.path.splitext(filename)
|
||||
return root.endswith('_thumb')
|
||||
|
||||
def thumbnail_name (filename):
|
||||
"""Return the thumbnail form of a filename,
|
||||
converting foo.jpg to foo_thumb.jpg.
|
||||
"""
|
||||
assert not is_thumbnail(filename)
|
||||
root, ext = os.path.splitext(filename)
|
||||
return root + '_thumb' + ext
|
||||
|
||||
def output_html (args):
|
||||
for filename in args:
|
||||
if is_thumbnail(filename): continue
|
||||
thumbnail = thumbnail_name(filename)
|
||||
|
||||
if not os.path.exists(thumbnail):
|
||||
print >>sys.stderr, ("%s: thumbnail %s doesn't exist" %
|
||||
(sys.argv[0], thumbnail) )
|
||||
|
||||
im = Image.open(thumbnail)
|
||||
width, height = im.size
|
||||
|
||||
print ('<p><a href="%s"><img src="%s" width="%i" height="%i" '
|
||||
'alt="XXX" align="XXX"></a>'
|
||||
'\n\nXXX\n'
|
||||
'<br clear=all><hr>\n\n'
|
||||
% (filename, thumbnail, width, height) )
|
||||
|
||||
def make_thumbnails (args):
|
||||
x, y = int(args[0]), int(args[1])
|
||||
args = args[2:] ; args.sort()
|
||||
|
||||
for filename in args:
|
||||
if is_thumbnail(filename): continue
|
||||
thumbnail = thumbnail_name(filename)
|
||||
|
||||
print >>sys.stderr, filename
|
||||
im = Image.open(filename)
|
||||
im.thumbnail((x,y))
|
||||
im.save(thumbnail)
|
||||
|
||||
def rotate_images (args):
|
||||
x = int(args[0])
|
||||
args = args[1:] ; args.sort()
|
||||
for filename in args:
|
||||
im = Image.open(filename)
|
||||
im2 = im.rotate(x)
|
||||
im2.save(filename)
|
||||
print "rotated %s %i degrees" % (filename, x)
|
||||
|
||||
def resize_images (args):
|
||||
x, y = int(args[0]), int(args[1])
|
||||
args = args[2:] ; args.sort()
|
||||
for filename in args:
|
||||
im = Image.open(filename)
|
||||
w,h = im.size
|
||||
im2 = im.resize((x,y))
|
||||
print >>sys.stderr, ('%s: was %i,%i; resizing to %i,%i'
|
||||
% (filename, w,h, x,y) )
|
||||
im2.save(filename)
|
||||
|
||||
|
||||
def main ():
|
||||
opts, args = getopt.getopt(sys.argv[1:],
|
||||
'h',
|
||||
['help',
|
||||
'html',
|
||||
'resize',
|
||||
'size',
|
||||
'thumbnail',
|
||||
'rotate'])
|
||||
|
||||
# Remove the unused option arguments
|
||||
opts = [opt for opt,arg in opts]
|
||||
|
||||
# Print usage message if requested
|
||||
if '-h' in opts or '--help' in opts:
|
||||
print >>sys.stderr, __doc__
|
||||
sys.exit(0)
|
||||
|
||||
# Ensure that exactly one option is supplied
|
||||
if len(opts) == 0:
|
||||
print >> sys.stderr, ("%s: must specify one of --size, --help"
|
||||
"\n --html, --resize, --thumbnail --rotate" %
|
||||
sys.argv[0] )
|
||||
sys.exit(0)
|
||||
elif len(opts) > 1:
|
||||
print >> sys.stderr, ("%s: cannot specify multiple options" %
|
||||
sys.argv[0] )
|
||||
sys.exit(0)
|
||||
|
||||
# Perform each of the possible actions
|
||||
opt = opts[0]
|
||||
if opt == '--html':
|
||||
output_html(args)
|
||||
elif opt == '--resize':
|
||||
resize_images(args)
|
||||
elif opt == '--rotate':
|
||||
rotate_images(args)
|
||||
elif opt == '--size':
|
||||
for filename in args:
|
||||
image = Image.open(filename)
|
||||
x, y = image.size
|
||||
print filename, ':', x,y
|
||||
elif opt == '--thumbnail':
|
||||
make_thumbnails(args)
|
||||
|
||||
else:
|
||||
print >>sys.stderr, ("%s: unknown option" % sys.argv[0])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
84
spielspass/normalizer.py
Executable file
84
spielspass/normalizer.py
Executable file
|
@ -0,0 +1,84 @@
|
|||
#!/usr/bin/env python
|
||||
## this is a dirty, lame hack by a dirty, lame guy
|
||||
## - reads a .m3u file (e.g. generated by xmms)
|
||||
## - converts any audiofile to wavefiles using incredible mplayer
|
||||
## - provides normalized wavefiles using transcode
|
||||
## - burns an audio-cd
|
||||
# !!feel free to copy, modify, redistribute and at most _use_ it!!
|
||||
# comments to: age-at-systemausfall-dot-org 02004
|
||||
|
||||
import os
|
||||
import string
|
||||
|
||||
m3ufile = "foo.m3u"
|
||||
wavdir = "/mnt/ionos/mugge/aufnahme/ready"
|
||||
recorder = "ATAPI:0,0,0" #fuer cdrecord mit 2.6 kernel und ide brenner
|
||||
|
||||
print "\nDirty, lame hack in action:\n"
|
||||
################
|
||||
### read m3u
|
||||
try:
|
||||
temp = open(m3ufile,"r")
|
||||
m3u = temp.read()
|
||||
temp.close()
|
||||
except:
|
||||
print "I can't find the .m3u file"
|
||||
# M's Kommentar Schnibbler
|
||||
notfound = 0
|
||||
while notfound == 0:
|
||||
startpos = string.find(m3u,"#")
|
||||
if startpos <0:
|
||||
notfound +=1
|
||||
endpos = string.find(m3u,"\n",startpos)
|
||||
cutme = m3u[startpos:endpos]
|
||||
m3u = string.replace(m3u,cutme,"")
|
||||
|
||||
valuepairs = string.split(m3u,"\n")
|
||||
m3u = []
|
||||
for i in valuepairs:
|
||||
if i != "":
|
||||
m3u.append(i)
|
||||
# im m3u-array stehen jetzt hoffentlich ;) nur noch pfadangaben
|
||||
# checken ob's stimmt
|
||||
for i in m3u:
|
||||
if not os.path.exists(i):
|
||||
print "===> %s not found!" % i
|
||||
print "I'll ignore it."
|
||||
m3u.remove(i)
|
||||
print "\nI found %i audiofiles to convert, normalize and burn:" % len(m3u)
|
||||
|
||||
##############
|
||||
### ogg -> wav
|
||||
count = 0
|
||||
for file in m3u:
|
||||
count+=1
|
||||
#TODO: count braucht fuehrende nullen, damit die reihenfolge auf der cd stimmt!!
|
||||
command = "mplayer \""+file+"\" -ao pcm -aofile "+wavdir+"/"+str(count)+".wav &> /dev/null"
|
||||
print "\nexec: "+command
|
||||
session = os.popen(command,"w")
|
||||
session.write("")
|
||||
session.flush()
|
||||
session.close()
|
||||
|
||||
#########################
|
||||
### wav -> normalized wav
|
||||
wavefiles = os.listdir(wavdir)
|
||||
for wave in wavefiles:
|
||||
command = "transcode -J normalize -y wav -i "+wavdir+"/"+wave+" -m "+wavdir+"/"+ wave+".norm &> /dev/null"
|
||||
|
||||
print "\nexec: "+command
|
||||
session = os.popen(command,"w")
|
||||
session.write("")
|
||||
session.flush()
|
||||
session.close()
|
||||
|
||||
##################
|
||||
### wav -> audiocd
|
||||
command = "sudo cdrecord -v -dev="+recorder+" -pad -audio "+wavdir+"/*.wav.norm"
|
||||
print "\nexec: "+command
|
||||
session = os.popen(command,"w")
|
||||
session.write("")
|
||||
session.flush()
|
||||
session.close()
|
||||
|
||||
print "\n That's it! Eine Stunde coden und dafuer jetzt den Sommer geniessen..."
|
Loading…
Reference in a new issue