from pil import image, imagedraw, imagefont im = image.open("spacetime.png") fnt = imagefont.truetype('pillow/tests/fonts/dejavusans.ttf', 18) draw = imagedraw.draw(im) draw.text((10,60), "world", font=fnt, fill=(0,0,0,255)) del draw im.save('hi', "png")
def content_hash(filename): '''return hash of rgba contents of image''' i = image.open(filename) i = i.convert('rgba') data = i.tostring() return hashlib.sha256(data).hexdigest()
# requires imagemagick 6.7+ from __future__ import division from os import path from pil import image from subprocess import popen src='img/reload.png' tmpdir='../../src/qt/res/movies/' tmpname='spinner-%03i.png' numframes=35 framerate=10.0 convert='convert' clockwise=true dsize=(16,16) im_src = image.open(src) if clockwise: im_src = im_src.transpose(image.flip_left_right) def frame_to_filename(frame): return path.join(tmpdir, tmpname % frame) frame_files = [] for frame in xrange(numframes): rotation = (frame + 0.5) / numframes * 360.0 if clockwise: rotation = -rotation im_new = im_src.rotate(rotation, image.bicubic) im_new.thumbnail(dsize, image.antialias) outfile = frame_to_filename(frame)