[BitBucket date: 2018-10-19.13:30:57] In order to export a preview as jpeg, you need to pass the `Accept: image/jpeg` header. `RestApiGet` does not support passing specific headers, and using `HttpGet` is not allowed to make calls to the local instance. Here's an example: ``` #!Lua function OnStoredInstance(instanceId, tags, metadata, origin) -- Generate a image preview of the DICOM file local png = RestApiGet('/instances/' .. instanceId .. '/preview') # This works! local headers = { ['Accept']='image/jpeg' } local jpeg = HttpGet('http://orthanc:foobar@localhost:8042/instances/' .. instanceId .. '/preview', headers) # This does not! end ```
[BitBucket user: Sébastien Jodogne] [BitBucket date: 2019-06-24.14:06:54] Fix issue #106 (Unable to export preview as jpeg from Lua script) → https://hg.orthanc-server.com/orthanc/changeset/dd1e68f2d0c0
[BitBucket user: Sébastien Jodogne] [BitBucket date: 2019-06-24.14:08:53] `RestApiGet()` now can be provided with HTTP headers. Full example: ```lua function Initialize() local instanceId= '19816330-cb02e1cf-df3a8fe8-bf510623-ccefe9f5' local png = RestApiGet('/instances/' .. instanceId .. '/preview', true) print('PNG size: ' .. string.len(png)) local headers = {} headers['Accept']='image/jpeg' local jpeg = RestApiGet('/instances/' .. instanceId .. '/preview', true, headers) print('JPEG size (default quality = 90): ' .. string.len(jpeg)) local jpeg50 = RestApiGet('/instances/' .. instanceId .. '/preview?quality=50', true, headers) print('JPEG size (quality 50): ' .. string.len(jpeg50)) headers['Accept']='image/x-portable-arbitrarymap' local pam = RestApiGet('/instances/' .. instanceId .. '/preview', true, headers) print('PAM size (uncompressed): ' .. string.len(pam)) end ```