Created
November 3, 2014 10:29
-
-
Save Hiromi-nee/a363ebd0331e292f03ab to your computer and use it in GitHub Desktop.
tkbctf4 monochrome_bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python2 | |
from sys import argv | |
from PIL import Image | |
im = Image.open(argv[1]) | |
imageW = im.size[0] | |
imageH = im.size[1] | |
pixels = im.load() | |
brute = [100, 108, 135, 150, 162, 180, 225, 243, 270, 300, 324, | |
405, 450, 486, 540, 675, 729] | |
for width in brute: | |
out_w = width | |
out_h = im.size[0]/width | |
img = Image.new(im.mode, | |
(out_w, out_h), | |
None | |
) | |
#y=height x=width | |
print '[+] Processing image size: {} x {}'.format(out_w, out_h) | |
h_count = 0 | |
w_count = 0 | |
for px in range(imageW): | |
if w_count == out_w: | |
#new height row | |
#print "w_count={}, h_count={}".format(w_count,h_count) | |
w_count = 0 | |
h_count += 1 | |
img.putpixel((w_count, h_count),pixels[px,0]) | |
w_count+=1 | |
print "Writing {}x{}".format(str(out_w), str(out_h)) | |
img.save('output_{}x{}.png'.format(str(out_w), str(out_h)), 'PNG') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment