Skip to content

Instantly share code, notes, and snippets.

@morris821028
Created April 18, 2016 06:11
Show Gist options
  • Save morris821028/e3dc82f8582eb25450f31f5e9a06f8a9 to your computer and use it in GitHub Desktop.
Save morris821028/e3dc82f8582eb25450f31f5e9a06f8a9 to your computer and use it in GitHub Desktop.
Image Process - Generator Testdata - Online Judge
import sys
import Image
import codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
for infile in sys.argv[1:]:
try:
im = Image.open(infile)
width = im.size[0]
height = im.size[1]
pix = im.load()
print height, width
for i in range(height):
for j in range(width):
print pix[j, i][0], pix[j, i][1], pix[j, i][2],
print
except IOError:
pass
import sys
import Image
import codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
with open(sys.argv[1]) as fin:
height, width = [int(x) for x in next(fin).split()]
img = Image.new('RGBA', (width, height))
array = []
for line in fin:
array.append([int(x) for x in line.split()])
pixels = img.load()
for i in range(height):
for j in range(width):
pixels[j, i] = (array[i][j*3], array[i][j*3+1], array[i][j*3+2], 255)
img.save('test.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment