Skip to content

Instantly share code, notes, and snippets.

@bwrsandman
Created January 14, 2015 17:21
Show Gist options
  • Save bwrsandman/c89bfd52853f89bfa6af to your computer and use it in GitHub Desktop.
Save bwrsandman/c89bfd52853f89bfa6af to your computer and use it in GitHub Desktop.
to_dev logo stamping for odoo
"""Using PIL add 'DEV' to the company (and the main odoo) logo
This is meant to be run as a script in the upgrade.py script of anybox.recipe.odoo
"""
from base64 import b64encode, b64decode
from cStringIO import StringIO
from PIL import Image, ImageDraw
main_partner = session.registry('ir.model.data').get_object(
session.cr, session.uid, 'base', 'main_partner')
if main_partner.image:
logo_data = b64decode(main_partner.image).strip()
img = Image.open(StringIO(logo_data))
else:
logo_img = Image.new('RGBA', (180, 180))
dev_img = Image.new('RGBA', (20, 13))
draw = ImageDraw.Draw(dev_img)
draw.text((1, 0), "DEV", (255, 0, 0, 180))
img = dev_img.resize(logo_img.size)
img = dev_img.rotate(45)
img.paste(dev_img, (0, 0), dev_img)
stringio = StringIO()
img.save(logo_stringio, format='png')
data = b64encode(logo_stringio.getvalue())
partner.write({'image': logo_data})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment