Orthanc Automatic Dicom to Jpeg Convertor

Good Morning Orthanc Friends

I have interesting concept/project that I wish to investigate.

I would like an automatic DICOM to JPEG convertor that acts as a Dicom send destination.

I require a program that allows an imaging modality to be able to send DICOM images to the applicatiion/Software (As it would a PACS destination) located on a PC or server, which automatically converts the images (x-ray only) and saves them in a file that would ideally be named or populated by Dicom tag (0010,0010)(patient Name)

It is basically a Interesting case folder creator, that X-ray users can send images from the modality to the converter destination for use as a teaching resource at a later date.

Could Orthanc be configured to we used in such a way?

I am a Radiographer not a programmer, but have slowly increased my knowledge by using some very basic features Orthanc for the last 12 months.

Any help and advise would be welcomed.

Best regards

Luke Whitty



This can very easily achieved with Lua scripting:

Here is a sample Lua script:

–TARGET = ‘/tmp/lua’
TARGET = ‘c:/temp/lua’ – For Windows

function OnStoredInstance(instanceId, tags, metadata, origin)
– Replace non-alphanumeric characters by underscore
local filename = string.gsub(tags[‘PatientName’], ‘[^a-zA-Z0-9]’, ‘_’)

– Suffix path with the instance ID to avoid overwriting duplicates (optional)
filename = filename … ‘-’ … instanceId

– Generate a PNG preview of the DICOM file
local png = RestApiGet(‘/instances/’ … instanceId … ‘/preview’)

– Write the PNG to the file
path = TARGET … ‘/’ … filename … ‘.png’
print('Writing image of the patient to: ’ … path)
local target = assert(io.open(path, ‘wb’))

– Remove the received DICOM instance from Orthanc (optional)
– Delete(instanceId)


Hi Sebastien,

I’m really glad that you help people here.

I would like some help to merge 2 scripts in order to generate a Folder with “PatientsName” and “ExamDate” and “PatientId” (now I’m using the one below, but it’s not exactyl what I need).

Then, inside the folder I would like to store the Dicom Files (could be flat architeture). And make another folder called “images” with PNG files.

At this moment I’m using this LUA script:

TARGET = ‘C:\Google Drive\Arquivos Clinica\Ultrassom\Imagens’

function ToAscii(s)
return s —I dont know what is this return

function OnStableSeries(seriesId, tags, metadata)
print('This series is now stable, writing its instances on the disk: ’ … seriesId)

local instances = ParseJson(RestApiGet(‘/series/’ … seriesId)) [‘Instances’]
local patient = ParseJson(RestApiGet(‘/series/’ … seriesId … ‘/patient’)) [‘MainDicomTags’]
local study = ParseJson(RestApiGet(‘/series/’ … seriesId … ‘/study’)) [‘MainDicomTags’]
local series = ParseJson(RestApiGet(‘/series/’ … seriesId)) [‘MainDicomTags’]

for i, instance in pairs(instances) do
local path = ToAscii(TARGET … ‘/’ …
patient[‘PatientID’] … ’ - ’ … patient[‘PatientName’] … ‘/’ …

– Retrieve the DICOM file from Orthanc
local dicom = RestApiGet(‘/instances/’ … instance … ‘/file’)

– Create the subdirectory (CAUTION: For Linux demo only, this is insecure!)
os.execute(‘mkdir "’ … path … ‘"’)

– Write to the file
local target = assert(io.open(path … ‘/’ … instance … ‘.dcm’, ‘wb’))

This Lua that I’m using makes a folder with patients ID and name (eg.: 000000045 - VITOR TESTE^^^^) I dont know why Philips Ultrasound makes this ^^^^ after the name.

It is possible to merge the one I’m using with this other script that you created in this topic for PNG exporting ?

I would like to create a Folder inside the patient folder with the PNG files with simple numeric sequence (1.png, 2.png …)
like this: C:\Google Drive\Arquivos Clinica\Ultrassom\Imagens\“path”\IMAGES\1.pgn

Thanks for the Help.

GD.lua (1.39 KB)


I feel that you have all the required information at your disposal: This is just Lua fine-tuning.

Give a try by yourself, then share your findings.