Mercurial > hg > orthanc-book
comparison Sphinx/source/plugins/python.rst @ 348:d8359cecdc89
pillow sample
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Mar 2020 12:20:40 +0100 |
parents | 04fae9d4b65f |
children | 60080d792f25 |
comparison
equal
deleted
inserted
replaced
347:04fae9d4b65f | 348:d8359cecdc89 |
---|---|
12 in C | 12 in C |
13 <https://hg.orthanc-server.com/orthanc/file/Orthanc-1.5.7/Plugins/Include/orthanc/OrthancCPlugin.h>`__ | 13 <https://hg.orthanc-server.com/orthanc/file/Orthanc-1.5.7/Plugins/Include/orthanc/OrthancCPlugin.h>`__ |
14 using the `Clang <https://en.wikipedia.org/wiki/Clang>`__ compiler | 14 using the `Clang <https://en.wikipedia.org/wiki/Clang>`__ compiler |
15 front-end. The coverage of the C SDK is about 75% (105 functions are | 15 front-end. The coverage of the C SDK is about 75% (105 functions are |
16 automatically wrapped in Python out of a total of 139 functions in C). | 16 automatically wrapped in Python out of a total of 139 functions in C). |
17 | |
18 This provides much more flexibility than the Lua scripts. | |
17 | 19 |
18 | 20 |
19 Samples | 21 Samples |
20 ------- | 22 ------- |
21 | 23 |
161 if changeType == orthanc.ChangeType.STABLE_STUDY: | 163 if changeType == orthanc.ChangeType.STABLE_STUDY: |
162 print('Stable study: %s' % resourceId) | 164 print('Stable study: %s' % resourceId) |
163 orthanc.RestApiPost('/modalities/sample/store', resourceId) | 165 orthanc.RestApiPost('/modalities/sample/store', resourceId) |
164 | 166 |
165 orthanc.RegisterOnChangeCallback(OnChange) | 167 orthanc.RegisterOnChangeCallback(OnChange) |
168 | |
169 | |
170 Render a thumbnail using PIL/Pillow | |
171 ................................... | |
172 | |
173 .. highlight:: python | |
174 | |
175 :: | |
176 | |
177 from PIL import Image | |
178 import io | |
179 import orthanc | |
180 | |
181 def DecodeInstance(output, uri, **request): | |
182 if request['method'] == 'GET': | |
183 # Retrieve the instance ID from the regular expression (*) | |
184 instanceId = request['groups'][0] | |
185 | |
186 # Render the instance, then open it in Python using PIL/Pillow | |
187 png = orthanc.RestApiGet('/instances/%s/rendered' % instanceId) | |
188 image = Image.open(io.BytesIO(png)) | |
189 | |
190 # Downsize the image as a 64x64 thumbnail | |
191 image.thumbnail((64, 64), Image.ANTIALIAS) | |
192 | |
193 # Save the thumbnail as JPEG, then send the buffer to the caller | |
194 jpeg = io.BytesIO() | |
195 image.save(jpeg, format = "JPEG", quality = 80) | |
196 jpeg.seek(0) | |
197 output.AnswerBuffer(jpeg.read(), 'text/plain') | |
198 | |
199 else: | |
200 output.SendMethodNotAllowed('GET') | |
201 | |
202 orthanc.RegisterRestCallback('/pydicom/(.*)', DecodeInstance) # (*) |