Last active
August 29, 2015 14:10
-
-
Save maluta/d00f388cdd11f97a31f5 to your computer and use it in GitHub Desktop.
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
# arte conceito com o instagram | |
# pega uma imagem e 'fatia' em 6 partes | |
# o arquivo 'cropinsta.html' mostra como vai ficar. | |
# veja o arquivo cropinsta.html (gerado após executar o programa) para ter uma idéia de como vai ficar. [não se esqueça de diminuir o zoom da página] | |
from PIL import Image | |
import sys | |
filename = "teste.jpg" | |
try: | |
filename = sys.argv[1] | |
except: | |
print(">>> especifique a foto") | |
print("$ python insta.py imagem.jpg") | |
exit() | |
img = Image.open( filename ) | |
''' | |
+----------+----------+----------+ | |
| | | | | |
| A | B | C | | |
| | | | | |
+----------+----------+----------+ | |
| | | | | |
| D | E | F | | |
| | | | | |
+----------+----------+----------+ | |
X = (left, upper, right, lower) | |
A = (0, 0, 612, 612) | |
B = (612, 0, 612+612, 612 | |
C = (612+612, 0, 612+612+612, 612) | |
D = (0, 612, 612, 612+612) | |
E = (612, 612, 612+612, 612+612) | |
F = (612+612, 612, 612+612+612, 612+612) | |
''' | |
boxes = [ (0, 0, 612, 612) , (612, 0, 612+612, 612), (612+612, 0, 612+612+612, 612), | |
(0, 612, 612, 612+612), (612, 612, 612+612, 612+612), (612+612, 612, 612+612+612, 612+612) ] | |
for i,box in enumerate(boxes): | |
r = img.crop( box ) | |
r.save("{0}.jpg".format(i)) | |
html = ''' | |
<html> | |
<head><title></title></head> | |
<body> | |
<table> | |
<tr> | |
<td><img src="{0}" /></td> | |
<td><img src="0.jpg" />.<img src="1.jpg" />.<img src="2.jpg" /> | |
<br> | |
<img src="3.jpg" />.<img src="4.jpg" />.<img src="5.jpg" /></td> | |
</tr> | |
</table> | |
</body> | |
</html> | |
'''.format( filename ) | |
with open("cropinsta.html",'w') as f: | |
f.writelines(html) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment