diff options
| author | Bobby <[email protected]> | 2022-11-22 09:17:56 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-11-22 09:17:56 -0500 |
| commit | 93033431d1c6a60b083c489a9b33ae4efe64ee03 (patch) | |
| tree | 671337d009a91f2f6d2d56dfe8c43dbb84ecee0e | |
| parent | edace8bf3afd080940d9a680a431c39e2c99522f (diff) | |
| download | thatcomputerscientist-93033431d1c6a60b083c489a9b33ae4efe64ee03.tar.xz thatcomputerscientist-93033431d1c6a60b083c489a9b33ae4efe64ee03.zip | |
compress image data
| -rw-r--r-- | ignis/views.py | 24 | ||||
| -rw-r--r-- | templates/dev_status/home.html | 6 |
2 files changed, 25 insertions, 5 deletions
diff --git a/ignis/views.py b/ignis/views.py index 67201aaf..9f539d05 100644 --- a/ignis/views.py +++ b/ignis/views.py @@ -51,10 +51,30 @@ def get_image(request, slug, md5): @csrf_exempt def cover_image(request, repository): - url = 'https://socialify.git.ci/luciferreeves/{}/png?font=KoHo&language=1&name=1&pattern=Floating%20Cogs&theme=Dark'.format(repository) + url = 'https://socialify.git.ci/luciferreeves/{}/png?font=KoHo&language=1&name=1&pattern=Solid&theme=Dark'.format(repository) image = requests.get(url).content - return HttpResponse(image, content_type='image/png') + + # reduce image size to 320x160 + image = Image.open(BytesIO(image)) + image = image.resize((320, 160), Image.ANTIALIAS) + + # remove black background + image = image.convert('RGBA').getdata() + new_data = [] + for item in image: + if item[0] == 0 and item[1] == 0 and item[2] == 0: + new_data.append((255, 255, 255, 0)) + else: + new_data.append(item) + + # Convert back to png and return + output = BytesIO() + image = Image.new('RGBA', (320, 160)) + image.putdata(new_data) + image.save(output, format='GIF') + return HttpResponse(output.getvalue(), content_type='image/gif') + def upload_image(request): if request.method == 'POST': diff --git a/templates/dev_status/home.html b/templates/dev_status/home.html index 91a00276..31b22a74 100644 --- a/templates/dev_status/home.html +++ b/templates/dev_status/home.html @@ -49,12 +49,12 @@ <table style="width=720px; margin: 0 auto; table-layout: fixed;"> {% for repo in repos %} <tr> - <td> - <a href="{% url 'dev_status:repo' repo.name %}" style="display: inline-block; margin-right: 10px; background-image: url('{% url 'ignis:cover_image' repo.name %}');" class="zoom"></a> + <td><a href="{% url 'dev_status:repo' repo.name %}"> + <img src="{% url 'ignis:cover_image' repo.name %}" style="display: inline-block; margin-right: 10px;" class="zoom"> </a> </td> <td> - <p style="font-size: 20px; font-weight: bold;">{{ repo.name }}</p> + <p style="font-size: 20px; font-weight: bold;"><a href="{% url 'dev_status:repo' repo.name %}">{{ repo.name }}</a></p> <p style="font-size: 15px;">{{ repo.description }}</p> </td> |
