From 7ee5ca85fc70eecc796680edee4d9cec07e4a4e8 Mon Sep 17 00:00:00 2001 From: Bobby Date: Thu, 17 Nov 2022 12:03:33 -0500 Subject: backgorund image change and change function display color --- blog/views.py | 15 +++++++++++++-- requirements.txt | 3 ++- static/css/main.css | 5 +++-- static/images/site/backgound.jpeg | Bin 0 -> 152897 bytes 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 static/images/site/backgound.jpeg diff --git a/blog/views.py b/blog/views.py index 26d75e69..e1113016 100644 --- a/blog/views.py +++ b/blog/views.py @@ -12,6 +12,8 @@ import json from .models import Post, Comment from .context_processors import recent_posts from announcements.models import Announcement +from PIL import Image +from io import BytesIO # Create your views here. @@ -178,6 +180,15 @@ def tex(request): import requests - image = requests.get('https://latex.codecogs.com/png.image?%5Cinline%20%5Clarge%20%5Cdpi%7B300%7D%5Cbg%7Bblack%7D' + expression).content + image = requests.get('https://latex.codecogs.com/png.image?%5Cinline%20%5Clarge%20%5Cdpi%7B300%7D%5Cbg%7Btransparent%7D' + expression).content - return HttpResponse(image, content_type='image/png') + # Image is a transparent GIF with black text. Invert the colors. + image = Image.open(BytesIO(image)) + image = image.convert('RGB') + image = Image.eval(image, lambda x: 255 - x) + image = image.convert('RGBA') + + # Convert back to gif and return + output = BytesIO() + image.save(output, format='GIF') + return HttpResponse(output.getvalue(), content_type='image/gif') diff --git a/requirements.txt b/requirements.txt index efee8138..47cbb152 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ six==1.16.0 cryptocode==0.1 captcha==0.4 PyGithub==1.55 -requests==2.28.1 \ No newline at end of file +requests==2.28.1 +pillow==9.2.0 \ No newline at end of file diff --git a/static/css/main.css b/static/css/main.css index 412b2358..ba0c9d16 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -1,8 +1,9 @@ body { - background-image: url("../images/site/bg.gif"); - background-repeat: repeat; + background-image: url("../images/site/backgound.jpeg"); + background-repeat: no-repeat; background-attachment: fixed; background-position: center; + background-size: cover; font-family: 'Times New Roman', Times, serif; padding: 0; margin: 0; diff --git a/static/images/site/backgound.jpeg b/static/images/site/backgound.jpeg new file mode 100644 index 00000000..90281bd8 Binary files /dev/null and b/static/images/site/backgound.jpeg differ -- cgit v1.2.3