Login

Snippets by dc

Snippet List

Load Windows ICO files

PIL IcoImagePlugin is twelve year old and it can't handle recent Windows ICO files. Here is a function that handles all ICO versions and preserve transparency. Usage: # Load biggest icon from file image = load_icon('icon.ico') # Save third icon as PNG load_icon('icon.ico', 2).save('icon.png')

  • image
  • pil
  • ico
Read More
Author: dc
  • 2
  • 2

Choices class

Yet another class to simplify field choices creation. Keeps order, allows i18n. Before: ONLINE = 0 OFFLINE = 1 STATES = ( (ONLINE, _('online')), (OFFLINE, _('offline')) ) state = models.IntegerField(choices=STATES, default=OFFLINE) After: STATES = Choices( ('ONLINE', _('online')), ('OFFLINE', _('offline')) ) state = models.IntegerField(choices=STATES, default=STATES.OFFLINE)

  • models
  • choices
Read More
Author: dc
  • 7
  • 8

dc has posted 2 snippets.