Skip to content

Instantly share code, notes, and snippets.

@nathan-sixnines
Last active April 19, 2017 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathan-sixnines/515e776e6bc71052960715f3c526e539 to your computer and use it in GitHub Desktop.
Save nathan-sixnines/515e776e6bc71052960715f3c526e539 to your computer and use it in GitHub Desktop.
from PIL import Image
im = Image.open('Flag_of_Maryland.svg.png')
left = Image.open('flag_left.png')
right = Image.open('flag_right.png')
count = 0
dimensions = im.size
area = 99999
oldX = 0
while(area > 1):
count = count + 1
rdimensions = right.size
ldimensions = left.size
round = 1
if count%3 == 0:
round = 0
left = left.resize(((rdimensions[0]/2)+round,(rdimensions[1]/2)+round))
right = right.resize(((rdimensions[0]/2)+round,(rdimensions[1]/2)+round))
if (count % 2 == 1): # if odd do right side
y = 0
x = oldX + rdimensions[0]
count2 = 0
while (y < dimensions[1]):
count2 = count2 + 1
box = (x, y, x+right.size[0],y+right.size[1])
im.paste(right, box)
height = im.size[1] / (2**count)
# tweaking height of sections so they line up
if count < 4:
height = height + 1
if count == 4:
if count2 % 2 != 0:
height = height + 1
if count == 5:
if count2 % 4 != 0:
height = height + 1
if count == 7:
if count2 % 4 != 0:
height = height + 1
if height > 1:
y = y + height
else:
y = y + 1
if (count % 2 == 0): # if do left if even
y = 0
x = oldX + rdimensions[0]
count2 = 0
while (y < dimensions[1]):
count2 = count2 + 1
box = (x, y, x+left.size[0],y+left.size[1])
im.paste(left, box)
height = im.size[1] / (2**count)
# tweaking height of sections so they line up
if count < 4:
height = height + 1
if count == 4:
if count2 % 2 != 0:
height = height + 1
if count == 6:
if count2 % 2 == 0 and count2 % 8 != 0:
height = height + 1
if height > 1:
y = y + height
else:
y = y + 1
oldX = x
area = left.size[0] * left.size[1]
if count > 100:
break
im.save('writeflag.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment