Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2013 11:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mpcabd/4529367 to your computer and use it in GitHub Desktop.
Code for Getting a pattern from an image in PIL (Python)
def get_pattern_from_image(file_name, pattern_width, pattern_height):
import Image
pattern_image =, 'r')
result_image ='RGB', (pattern_width, pattern_height))
x = 0
while x < pattern_width:
y = 0
while y < pattern_height:
result_image.paste(pattern_image, (x, y))
y += pattern_image.size[1]
x += pattern_image.size[0]
return result_image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment