Skip to content

Commit d8a5f7e

Browse files
committed
v0.0.1
0 parents  commit d8a5f7e

10 files changed

+1941
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist/
2+
build/
3+
*.egg-info*
4+
*.pyc
5+
output.png

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 0xflotus
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

Whitespace-only changes.

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Hashpic
2+
3+
Hashpic creates an image from the MD5 hash of your input.
4+
5+
### Usage
6+
7+
```bash
8+
> hashpic 'Hashpic rocks!'
9+
```
10+
11+
This should create a file `output.png` in your current directory.
12+
The input `Hashpic rocks!` should create the following image:
13+
14+
![hashpic image](./rocks.png)

hashpic/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.0.1"

hashpic/__main__.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import argparse
2+
from PIL import Image
3+
import os
4+
import hashlib
5+
from .util import *
6+
7+
def main():
8+
parser = argparse.ArgumentParser(description="Create an image from a md5 hash")
9+
parser.add_argument("input", help="Input")
10+
args = parser.parse_args()
11+
12+
hash = hashlib.md5(args.input.encode()).hexdigest()
13+
14+
colors = []
15+
for i in chunk_it(hash):
16+
colors.append(convert_term_to_rgb(int(i, 16)))
17+
18+
width = 1024
19+
height = 1024
20+
21+
im = Image.new(mode="RGB", size=(width, height), color="#ffffff")
22+
pixels = im.load()
23+
for x in range(width):
24+
for y in range(height):
25+
if x < 0x100 and y < 0x100:
26+
pixels[x, y] = colors[0]
27+
elif x < 0x200 and y < 0x100:
28+
pixels[x, y] = colors[1]
29+
elif x < 0x300 and y < 0x100:
30+
pixels[x, y] = colors[2]
31+
elif x < 0x400 and y < 0x100:
32+
pixels[x, y] = colors[3]
33+
elif x < 0x100 and y < 0x200:
34+
pixels[x, y] = colors[4]
35+
elif x < 0x200 and y < 0x200:
36+
pixels[x, y] = colors[5]
37+
elif x < 0x300 and y < 0x200:
38+
pixels[x, y] = colors[6]
39+
elif x < 0x400 and y < 0x200:
40+
pixels[x, y] = colors[7]
41+
elif x < 0x100 and y < 0x300:
42+
pixels[x, y] = colors[8]
43+
elif x < 0x200 and y < 0x300:
44+
pixels[x, y] = colors[9]
45+
elif x < 0x300 and y < 0x300:
46+
pixels[x, y] = colors[10]
47+
elif x < 0x400 and y < 0x300:
48+
pixels[x, y] = colors[11]
49+
elif x < 0x100 and y < 0x400:
50+
pixels[x, y] = colors[12]
51+
elif x < 0x200 and y < 0x400:
52+
pixels[x, y] = colors[13]
53+
elif x < 0x300 and y < 0x400:
54+
pixels[x, y] = colors[14]
55+
elif x < 0x400 and y < 0x400:
56+
pixels[x, y] = colors[15]
57+
else:
58+
pixels[x, y] = (0xFF, 0xFF, 0xFF)
59+
im.show()
60+
im.save(os.getcwd() + "/output.png")
61+
62+
63+
if __name__ == "__main__":
64+
main()

0 commit comments

Comments
 (0)