mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-10 06:52:24 +01:00
api: Add image endpoint for use on tosti.science.ru.nl
This commit is contained in:
@ -8,7 +8,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from django.db import transaction
|
||||
from django.db.models import Q, Sum, Value
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.http import JsonResponse, HttpResponseForbidden
|
||||
from django.http import JsonResponse, HttpResponseForbidden, HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.views.decorators.cache import cache_page
|
||||
from django.views.decorators.http import require_http_methods
|
||||
@ -349,3 +349,26 @@ def _request_weight(ps):
|
||||
return float(ps.song.duration)
|
||||
# Count other requests for 10%
|
||||
return 0.10 * float(ps.song.duration)
|
||||
|
||||
|
||||
def queue_png(request):
|
||||
current_song = request.user.queue.current_song()
|
||||
|
||||
requestor = 'Marietje' if current_song.user is 'Marietje' else 'privacy™' # Anonymous
|
||||
artist, title = current_song.song.artist, current_song.song.title
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
width, height = 640, 480
|
||||
ttf = 'marietje/static/fonts/comic-serif.tff'
|
||||
zuidSerifRequestor = ImageFont.truetype(ttf, 64)
|
||||
zuidSerifArtist = ImageFont.truetype(ttf, 80)
|
||||
zuidSerifTitle = ImageFont.truetype(ttf, 64)
|
||||
img = Image.new('RGB', (width, height), color='#BE311A')
|
||||
imgDraw = ImageDraw.Draw(img)
|
||||
imgDraw.text((10, 110), requestor, fill='#FFFFFF', font=zuidSerifRequestor)
|
||||
imgDraw.text((10, 200), artist, fill='#FFFFFF', font=zuidSerifArtist)
|
||||
imgDraw.text((10, 280), title, fill='#FFFFFF', font=zuidSerifTitle)
|
||||
|
||||
response = HttpResponse(content_type='image/png')
|
||||
img.save(response, 'png')
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user