<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>PIL on Abdullah Diab&#39;s Blog</title>
    <link>https://mpcabd.xyz/tags/pil/</link>
    <description>Recent content in PIL on Abdullah Diab&#39;s Blog</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 14 Jan 2013 11:14:23 +0000</lastBuildDate>
    <atom:link href="https://mpcabd.xyz/tags/pil/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Get Pattern From an Image in PIL Python</title>
      <link>https://mpcabd.xyz/get-pattern-from-an-image-in-pil-python/</link>
      <pubDate>Mon, 14 Jan 2013 11:14:23 +0000</pubDate>
      <guid>https://mpcabd.xyz/get-pattern-from-an-image-in-pil-python/</guid>
      <description>&lt;p&gt;Two days ago I needed to generate a PIL image that is made up from repeating a pattern – another PIL image – multiple times, I didn’t find a code online to do it so I just wrote this small code to do it, thought might share it to help somebody out there.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>Two days ago I needed to generate a PIL image that is made up from repeating a pattern – another PIL image – multiple times, I didn’t find a code online to do it so I just wrote this small code to do it, thought might share it to help somebody out there.</p>
<pre class="lang:python decode:true">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 &lt; pattern_width:
        y = 0
        while y &lt; pattern_height:
            result_image.paste(pattern_image, (x, y))
            y += pattern_image.size[1]
        x += pattern_image.size[0]
    return result_image
</pre>
<p>It&rsquo;s a very simple solution which uses the <a href="http://www.pythonware.com/library/pil/handbook/image.htm#Image.paste" title="The Image Module - Paste" target="_blank">Image.paste</a> method to repeat the pattern.</p>
<p>You can download this snippet of code from here: <a href="https://gist.github.com/4529367" target="_blank"><a href="https://gist.github.com/4529367">https://gist.github.com/4529367</a></a>.</p>
<p>Enjoy 🙂</p>]]></content:encoded>
    </item>
  </channel>
</rss>
