title: Merge large images on disk
body: <h2>The main problem:</h2>
  
  <p>I have a map step where I render a large amount of sectors of an image in parallel:</p>
  
  <pre><code>1 2
  3 4
  
  worker a -&gt; 1
  worker b -&gt; 2
  ...
  
  merge 1,2,3,4 to make final image
  </code></pre>
  
  <h2>If it can fit in memory</h2>
  
  <p>With images that are relatively small and can fit in RAM, one can simply use PIL's functionality:</p>
  
  <pre><code>def merge_images(image_files, x, y):
      images = map(Image.open, image_files)
      width, height = images[0].size    
      new_im = Image.new('RGB', (width * x, height * y))
      for n, im in enumerate(images):
          new_im.paste(im, ((n%x) * width, (n//y) * height))
      return new_im
  </code></pre>
  
  <p>Unfortunately, I am going to have <em>many, many large sectors</em>. I want to merge the pictures finally into a single image of about 40,000 x 60,000 pixels, which I estimate to be around 20 GB's. (Or maybe even more)</p>
  
  <p>So obviously, we can't approach this problem on RAM. I know there are alternatives like <code>memmap</code>'ing arrays and writing to slices, which I will try. However, <strong>I am looking for as-out-of-the-box-as-possible solutions</strong>.</p>
  
  <p>Does anyone know of any easier alternatives? <strong>Even though all the approaches I've tried so far is in python, it doesn't need to be in python</strong>.</p>