title: Python PIL how to paste an image in all black square
body: <p>The goal is to paste a transparent PNG file on a base image that is 1000 x 1000. My code so far pastes an image that is 250 x 250 on to the base image but is randomly placed throughout the base image. The outcome looks like this <a href="https://i.stack.imgur.com/fpJTE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fpJTE.jpg" alt="enter image description here"></a></p>
  
  <p>Here is a a peice of the code so you guys can see what is going on.</p>
  
  <pre><code>import random
  from PIL import Image, ImageDraw, ImageOps, ImageFont 
  
  ###This creates the base image ###
  base = Image.new('RGB',(1000,1000),'black')
  base.save('base_image.jpg')
  
  ### Opens up all the images that will be used###
  jon = Image.open('jon_snow.jpg')
  rejon = Image.open('resized_jon.jpg')
  wolf = Image.open('wolf.png')
  
  
  ### The List of locations around the base image ###
  location = [(0,0),(0,250),(0,500),(0,750),(250,0),(250,250),(250,500),(250,750),(500,0),(500,250),(500,500),(500,750),(750,0),(750,250),(750,500),(750,750),(0,0),(0,250),(0,500),(0,750),(250,0),(250,250),(250,500),(250,750),(500,0),(500,250),(500,500),(500,750),(750,0),(750,250),(750,500),(750,750)]
  ### Opertaions used ###
  def image_resize(image,size):
    image.resize((size))
    image.save('resized_jon.jpg')
    return
  
  
  def image_invert(image):
    inverted = ImageOps.invert(image)
    base.paste(inverted,random.choice(location))
    base.save('base_image.jpg')
    return
  
  def fill_base():
    for x in range(6):
      image_invert(rejon)
  </code></pre>
  
  <p>I didnt add all the operations just to save time. So as you can see when the random is used it doesnt fill up all the black squares all the time it is generated. So that is whne i want to create a for loop maybe or something to check when those squares are black so then i can paste a PNG file there at that location. Is it possible to check for those black squares? Any help     </p>