diff options
| author | Bobby <[email protected]> | 2022-11-18 15:12:23 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-11-18 15:12:23 -0500 |
| commit | dae9aac1bcaeaab86649051cd0ab56a9fecbf63c (patch) | |
| tree | 18f957cd3f5f243ff99e4fda8e1fa9de0dca572b /ignis | |
| parent | 09537c60fdcd90431810d5debb5baf2886363052 (diff) | |
| download | thatcomputerscientist-dae9aac1bcaeaab86649051cd0ab56a9fecbf63c.tar.xz thatcomputerscientist-dae9aac1bcaeaab86649051cd0ab56a9fecbf63c.zip | |
rename module
Diffstat (limited to 'ignis')
| -rw-r--r-- | ignis/__init__.py | 0 | ||||
| -rw-r--r-- | ignis/admin.py | 3 | ||||
| -rw-r--r-- | ignis/apps.py | 6 | ||||
| -rw-r--r-- | ignis/migrations/__init__.py | 0 | ||||
| -rw-r--r-- | ignis/models.py | 3 | ||||
| -rw-r--r-- | ignis/tests.py | 3 | ||||
| -rw-r--r-- | ignis/urls.py | 8 | ||||
| -rw-r--r-- | ignis/views.py | 39 |
8 files changed, 62 insertions, 0 deletions
diff --git a/ignis/__init__.py b/ignis/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/ignis/__init__.py diff --git a/ignis/admin.py b/ignis/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/ignis/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/ignis/apps.py b/ignis/apps.py new file mode 100644 index 00000000..8c2eea77 --- /dev/null +++ b/ignis/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class IgnisConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'ignis' diff --git a/ignis/migrations/__init__.py b/ignis/migrations/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/ignis/migrations/__init__.py diff --git a/ignis/models.py b/ignis/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/ignis/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/ignis/tests.py b/ignis/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/ignis/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/ignis/urls.py b/ignis/urls.py new file mode 100644 index 00000000..4e931c4d --- /dev/null +++ b/ignis/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from . import views + +app_name = 'ignis' +urlpatterns = [ + path('tex/', views.tex, name='tex'), + path('post_image/<int:post_id>/', views.post_image, name='post_image'), +] diff --git a/ignis/views.py b/ignis/views.py new file mode 100644 index 00000000..ffbce848 --- /dev/null +++ b/ignis/views.py @@ -0,0 +1,39 @@ +from django.shortcuts import render +from PIL import Image +from io import BytesIO +from django.http import HttpResponse +from django.views.decorators.csrf import csrf_exempt +import base64 +from blog.models import Post + +# Create your views here. +@csrf_exempt +def tex(request): + # get expression from request query + expression = request.GET.get('expr').replace('"', '').strip() + if not expression: + return HttpResponse('No expression provided!', status=400) + + import requests + + image = requests.get('https://latex.codecogs.com/png.image?%5Cinline%20%5Clarge%20%5Cdpi%7B300%7D%5Cbg%7Btransparent%7D' + expression).content + + # Image is a transparent GIF with black text. Invert the colors. + image = Image.open(BytesIO(image)) + image = image.convert('RGBA') + image = Image.eval(image, lambda x: 255 - x) + + # Convert back to gif and return + output = BytesIO() + image.save(output, format='GIF') + return HttpResponse(output.getvalue(), content_type='image/gif') + +@csrf_exempt +def post_image(request, post_id): + pi = Post.objects.get(id=post_id).post_image + if not pi: + return HttpResponse('No image found!', status=404) + + # convert base64 data src to image + image = base64.b64decode(pi.split(',')[1]) + return HttpResponse(image, content_type='image/png') |
