Skip to content

Commit aaa5808

Browse files
committed
Initial Commit
0 parents  commit aaa5808

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+534
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
api/robohash

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 Colin Davis
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
13+
all 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
21+
THE SOFTWARE.

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# A Simple Inclusive Avatar Generator
2+
3+
This is a really simple avatar generator I created for my last project. It's been incredibly helpful for all my new projects too so I decided to tidy it up a bit and make it available for anyone to use.
4+
5+
You create images with - [avatar.windsor.io/{anything}](https://avatar.windsor.io/{anything}).
6+
7+
`{anything}` can be anything, like an email address, user id, full name, url, ssn, etc.
8+
9+
For a given path, you'll always get back the same image, which is what makes this a great default avatar to use on your site.
10+
11+
I often use [avatar.windsor.io/{user.email}](avatar.windsor.io/{user.email}) as a default for most of my apps so the avatar for that user is consistent across any product of mine they use (and now your products too)!
12+
13+
## To deploy this yourself
14+
15+
### Setup
16+
17+
1. Clone repo
18+
2. `pip install -r requirements.txt`
19+
3. `./build-robohash.sh`
20+
21+
### If you want to make your own changes to the avatar images
22+
23+
1. Change the assets in `robohash-src/robohash/sets`
24+
2. `./build-robohash.sh`
25+
26+
### To deploy
27+
28+
#### With Vercel
29+
30+
1. Modify the alias field in `now.json` to wherever you want to deploy it to
31+
2. `vercel --prod`
32+
33+
#### On a different deployment platform
34+
35+
1. Simulate the vercel behaviour with `rewrites` in now.json and loading/serving the api routes in `api`.
36+
You can do this with writing your own server, or using AWS API Gateway or cloudflare workers or anything else you'd like :)
37+
2. Deploy, both the server code above, and the static resources (index.html and robots.txt)

api/index.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from http.server import BaseHTTPRequestHandler
2+
from .robohash import Robohash
3+
4+
5+
class handler(BaseHTTPRequestHandler):
6+
def do_GET(self):
7+
hash = self.path
8+
rh = Robohash(hash)
9+
rh.assemble(roboset="set1", sizex=300, sizey=300)
10+
self.send_response(200)
11+
self.send_header("Content-type", "image/png")
12+
self.end_headers()
13+
rh.img.save(self.wfile, format="png")
14+
return

build-robohash.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
set -euo pipefail
4+
5+
rm -rf api/robohash
6+
cd robohash-src
7+
python3 setup.py build
8+
cd ..
9+
mv robohash-src/build/lib/robohash api
10+
rm -r robohash-src/build

index.html

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Avatars</title>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="description" content="Generate inclusive Avatars for users" />
8+
<style>
9+
* {
10+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
11+
Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
12+
}
13+
</style>
14+
</head>
15+
<body>
16+
<img
17+
width="100"
18+
src="/*"
19+
alt="light skin man with red shirt and beard"
20+
/>
21+
<img
22+
width="130"
23+
src="/4"
24+
alt="dark skin woman with yellow shirt and ponytail"
25+
/>
26+
<img
27+
width="160"
28+
src="/girlme"
29+
alt="tanned woman with grey shirt and long hair"
30+
/>
31+
<img
32+
width="130"
33+
src="/9"
34+
alt="dark tanned man with red shirt and hair spray"
35+
/>
36+
<img
37+
width="100"
38+
src="/10"
39+
alt="light skin man with pink shirt and sunglasses"
40+
/>
41+
<h2>avatar.windsor.io/*</h2>
42+
<h3>The Inclusive Avatar Generator</h3>
43+
<p>
44+
Generate unique avatars. You can use any valid URL like
45+
<a href="avatar.windsor.io/abcd">avatar.windsor.io/abcd</a> or
46+
<a href="avatar.windsor.io/[email protected]"
47+
>avatar.windsor.io/[email protected]</a
48+
>
49+
and this app will spit out a .png image you can use as as a placeholder
50+
avatar. The same URL will always give you the same image, so this works
51+
really well as default profile pictures when you only have a user's ID or
52+
email.
53+
</p>
54+
<p>We use this throughout <a href="https://windsor.io">windsor.io</a></p>
55+
56+
<h3>Construction</h3>
57+
<p>Avatars are constructed using these parts</p>
58+
<img
59+
width="600"
60+
src="https://cdn.windsor.io/avatar/space.png"
61+
alt="a figure with all the various parts which are used to generate the avatars"
62+
/>
63+
</body>
64+
</html>

now.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": 2,
3+
"name": "avatar",
4+
"alias": "avatar.windsor.io",
5+
"rewrites": [{ "source": "/(.*)", "destination": "/api/" }],
6+
"files": ["api", "index.html", "robots.txt"]
7+
}

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pillow
2+
tornado
3+
natsort

robohash-src/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.pyc
2+
*.swp
3+
.DS_Store
4+
*.Pluric*Settings*
5+
nohup.out
6+
__pycache__
7+
build

robohash-src/LICENSE.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 Colin Davis
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
13+
all 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
21+
THE SOFTWARE.
22+

robohash-src/README.rst

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
RoboHash
2+
========
3+
4+
The source code for `RoboHash.org`_.
5+
6+
It basically copy/pastes various robot pictures together, using bits
7+
from the SHA hash. It's not perfect, and not entirely secure, but it
8+
gives a good gut-check to "Hey, this SHA is wrong."
9+
10+
Install
11+
-------
12+
13+
Just the library:
14+
15+
.. code:: bash
16+
17+
$ pip install robohash
18+
19+
Or if you also want the web frontend:
20+
21+
.. code:: bash
22+
23+
$ pip install robohash[web]
24+
25+
Usage
26+
-----
27+
28+
.. code:: python
29+
30+
from robohash import Robohash
31+
32+
hash = "whatever-hash-you-want"
33+
rh = Robohash(hash)
34+
rh.assemble(roboset='any')
35+
with open("path/to/new/file.png", "wb") as f:
36+
rh.img.save(f, format="png")
37+
38+
Robosets
39+
--------
40+
41+
RoboHash comes with five image sets, named "set1", "set2", "set3", "set4" and "set5".
42+
Specify which set you want in the ``assemble()`` method. Alternatively,
43+
specify the string "any", and RoboHash will pick an image set for you,
44+
based on the provided hash.
45+
46+
47+
License
48+
-------
49+
50+
The Python Code is available under the MIT/Expat license. See the
51+
``LICENSE.txt`` file for the full text of this license. Copyright (c)
52+
2011, Colin Davis.
53+
54+
The RoboHash images are available under license-
55+
56+
The "set1" artwork was created by Zikri Kader.
57+
They are available under CC-BY-3.0 or CC-BY-4.0 license.
58+
59+
The "set2" artwork was created by Hrvoje Novakovic.
60+
They are available under CC-BY-3.0 license.
61+
62+
The "set3" artwork was created by Julian Peter Arias.
63+
They are available under CC-BY-3.0 license.
64+
65+
The Cats/"set4" were created by David Revoy, used under CC-BY-4.0
66+
https://www.peppercarrot.com/en/article391/cat-avatar-generator
67+
68+
The avatars used in "set5" were created by Pablo Stanley, for https://avataaars.com/
69+
They are "Free for personal and commercial use. 😇"
70+
71+
72+
73+
74+
Disclaimer
75+
----------
76+
77+
OK, I'll admit I'm a crappy programmer. Compounding this, I wrote this
78+
code initially to be internal-only. It's ugly, and could be a LOT nicer.
79+
80+
Sorry about that.
81+
82+
.. _RoboHash.org: https://robohash.org/

robohash-src/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pillow
2+
tornado
3+
natsort

robohash-src/robohash/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .robohash import Robohash
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

robohash-src/robohash/cli.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import argparse
2+
import io
3+
import sys
4+
from robohash import Robohash
5+
6+
7+
def main():
8+
parser = argparse.ArgumentParser()
9+
parser.add_argument("-s", "--set", default="set1")
10+
parser.add_argument("-x", "--width", type=int, default=300)
11+
parser.add_argument("-y", "--height", type=int, default=300)
12+
parser.add_argument("-f", "--format", default="png")
13+
parser.add_argument("-b", "--bgset")
14+
parser.add_argument("-o", "--output", default="robohash.png")
15+
parser.add_argument("text", help="Text to use for the hash")
16+
17+
args = parser.parse_args()
18+
19+
robohash = Robohash(args.text)
20+
robohash.assemble(roboset=args.set, bgset=args.bgset,
21+
sizex=args.width, sizey=args.height)
22+
23+
robohash.img.save(args.output, format=args.format)
24+
25+
if __name__ == "__main__":
26+
main()

robohash-src/robohash/restart.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
killall python
2+
nohup ./webfront.py --port=8080 >/dev/null &
3+
nohup ./webfront.py --port=8081 >/dev/null &
4+
nohup ./webfront.py --port=8082 >/dev/null &
5+
nohup ./webfront.py --port=8083 >/dev/null &

0 commit comments

Comments
 (0)