Mercurial > hg > orthanc-book
comparison Sphinx/source/plugins/python/pil.py @ 703:a589668768d7
moving python samples in separate files (2)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 11 Jun 2021 10:07:12 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
702:6e02cd89eb6a | 703:a589668768d7 |
---|---|
1 from PIL import Image | |
2 import io | |
3 import orthanc | |
4 | |
5 def DecodeInstance(output, uri, **request): | |
6 if request['method'] == 'GET': | |
7 # Retrieve the instance ID from the regular expression (*) | |
8 instanceId = request['groups'][0] | |
9 | |
10 # Render the instance, then open it in Python using PIL/Pillow | |
11 png = orthanc.RestApiGet('/instances/%s/rendered' % instanceId) | |
12 image = Image.open(io.BytesIO(png)) | |
13 | |
14 # Downsize the image as a 64x64 thumbnail | |
15 image.thumbnail((64, 64), Image.ANTIALIAS) | |
16 | |
17 # Save the thumbnail as JPEG, then send the buffer to the caller | |
18 jpeg = io.BytesIO() | |
19 image.save(jpeg, format = "JPEG", quality = 80) | |
20 jpeg.seek(0) | |
21 output.AnswerBuffer(jpeg.read(), 'text/plain') | |
22 | |
23 else: | |
24 output.SendMethodNotAllowed('GET') | |
25 | |
26 orthanc.RegisterRestCallback('/pydicom/(.*)', DecodeInstance) # (*) |