Skip to content

Commit

Permalink
Generate image in get_image_from_mock_server instead of using a stati…
Browse files Browse the repository at this point in the history
…c file
  • Loading branch information
TerryvanWalen committed May 13, 2024
1 parent a12e32b commit 590a51c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ WORKDIR /app_install
ADD requirements_dev.txt requirements_dev.txt
RUN pip install -r requirements_dev.txt

RUN mkdir -p /static && chown datapunt /static

WORKDIR /src
USER datapunt

Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ services:
USE_JWKS_TEST_KEY: 'true'
MOCK_GET_IMAGE_FROM_SERVER: 'true'
METADATA_SERVER_BASE_URL: 'http://metadata-server:8000'
volumes:
- ./static:/static
command: python manage.py runserver 0.0.0.0:8000

test:
Expand Down
13 changes: 10 additions & 3 deletions src/iiif/image_server.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging
import re
from io import BytesIO

import requests
from django.conf import settings
from django.http import HttpResponse
from PIL import Image
from requests.exceptions import RequestException

from main.utils import ImmediateHttpResponse
Expand Down Expand Up @@ -43,11 +45,16 @@ def create_file_url_and_headers(url_info, metadata):

# For develop/test environments where we don't have access to the upstream server
def get_image_from_mock_server():
# Create an image
img = Image.new("RGB", (32, 32), color="green")
buf = BytesIO()
img.save(buf, format="JPEG")
img_bytes = buf.getvalue()

response = requests.Response()
response.status_code = 200
with open(settings.STATIC_IMAGE, "rb") as f:
response._content = f.read()
response.headers["Content-Type"] = "image/png"
response.headers["Content-Type"] = "image/jpeg"
response._content = img_bytes
return response


Expand Down
Binary file removed static/example.jpg
Binary file not shown.

0 comments on commit 590a51c

Please sign in to comment.