Skip to content

Instantly share code, notes, and snippets.

@n1ckfg
Last active January 22, 2018 15:10
Show Gist options
  • Select an option

  • Save n1ckfg/58b5425a1b81aa3c60c3d3af7703eb3b to your computer and use it in GitHub Desktop.

Select an option

Save n1ckfg/58b5425a1b81aa3c60c3d3af7703eb3b to your computer and use it in GitHub Desktop.
Python Imaging Library / PIL / Pillow hello-world
# http://effbot.org/imagingbook/introduction.htm
# https://en.wikibooks.org/wiki/Python_Imaging_Library/Editing_Pixels
import PIL.Image as Image
inputFilePath = "test.jpg"
outputFilePath = "out.png"
img = Image.open(inputFilePath)
print (str(img.format) + " " + str(img.size) + " " + str(img.mode))
box = (100,100,400,400)
region = img.crop(box)
region = region.transpose(Image.ROTATE_180)
img.paste(region, box)
pixels = img.load()
for i in range(img.size[0]):
for j in range(img.size[1]):
c = list(pixels[i,j])
c[0] += i
c[1] += j
c[2] += 0
pixels[i,j] = tuple(c)
img.save(outputFilePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment