Skip to content

Instantly share code, notes, and snippets.

@mpcabd
Created January 14, 2013 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpcabd/4529367 to your computer and use it in GitHub Desktop.
Save mpcabd/4529367 to your computer and use it in GitHub Desktop.
Code for http://mpcabd.igeex.biz/get-pattern-from-an-image-in-pil-python/ Getting a pattern from an image in PIL (Python)
def get_pattern_from_image(file_name, pattern_width, pattern_height):
import Image
pattern_image = Image.open(file_name, 'r')
result_image = Image.new('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