import optparse, math, sys
-import ImageFilter, ImageChops, Image, ImageDraw, ImageColor
+import ImageFilter, ImageChops, Image, ImageDraw, ImageColor, ImageEnhance
import numpy
from timeside.core import FixedSizeInputAdapter
self.draw_peaks(self.pixel_cursor, peaks, spectral_centroid)
self.pixel_cursor += 1
+ def watermark(self, text, color=None, opacity=.6, margin=(10,10)):
+ self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin)
+
def save(self, filename):
""" Apply last 2D transforms and write all pixels to the file. """
if eod:
self.draw_peaks_contour()
+ def watermark(self, text, color=None, opacity=.6, margin=(10,10)):
+ self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin)
+
def save(self, filename):
""" Apply last 2D transforms and write all pixels to the file. """
# middle line (0 for none)
self.draw_peaks(self.pixel_cursor, (0, 0))
self.pixel_cursor += 1
+ def watermark(self, text, color=None, opacity=.6, margin=(10,10)):
+ self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin)
+
def save(self, filename):
""" Apply last 2D transforms and write all pixels to the file. """
(spectral_centroid, db_spectrum) = self.spectrum.process(samples, True)
self.draw_spectrum(self.pixel_cursor, db_spectrum)
self.pixel_cursor += 1
+
+ def watermark(self, text, color=None, opacity=.6, margin=(10,10)):
+ self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin)
def save(self, filename):
""" Apply last 2D transforms and write all pixels to the file. """
y = numpy.convolve(w/w.sum(), s, mode='same')
return y[window_len-1:-window_len+1]
+def reduce_opacity(im, opacity):
+ """Returns an image with reduced opacity."""
+ assert opacity >= 0 and opacity <= 1
+ if im.mode != 'RGBA':
+ im = im.convert('RGBA')
+ else:
+ im = im.copy()
+ alpha = im.split()[3]
+ alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
+ im.putalpha(alpha)
+ return im
+
+def im_watermark(im, inputtext, font=None, color=None, opacity=.6, margin=(30,30)):
+ """
+ imprints a PIL image with the indicated text in lower-right corner
+ """
+ if im.mode != "RGBA":
+ im = im.convert("RGBA")
+ textlayer = Image.new("RGBA", im.size, (0,0,0,0))
+ textdraw = ImageDraw.Draw(textlayer)
+ textsize = textdraw.textsize(inputtext, font=font)
+ textpos = [im.size[i]-textsize[i]-margin[i] for i in [0,1]]
+ textdraw.text(textpos, inputtext, font=font, fill=color)
+ if opacity != 1:
+ textlayer = reduce_opacity(textlayer,opacity)
+ return Image.composite(textlayer, im, textlayer)
@interfacedoc
def setup(self, channels=None, samplerate=None, nframes=None):
super(WaveformJoyDiv, self).setup(channels, samplerate, nframes)
-# if self.graph:
-# self.graph = None
self.graph = WaveformImageJoyContour(self.width, self.height, self.nframes(), self.samplerate(), self.FFT_SIZE,
bg_color=self.bg_color, color_scheme=self.color_scheme, ndiv=self.ndiv, symetry=self.symetry)
def release(self):
self.graph.release()
+
+ def watermark(self, text, font=None, color=(255, 255, 255), opacity=.6, margin=(5,5)):
+ self.graph.watermark(text, color=color, opacity=opacity, margin=margin)