« Easier multi transfer… | Home | Comparing DynaPDF vs … »

Create thumbnail with GraphicsMagick

Here is a snippet we showed on the FMTraining live stream yesterday and it may be interesting for everyone here:

Set Variable [ $image ; Value: MBS( "GMImage.NewFromContainer"; $input) ] 

If [ MBS("IsError") = 0 ] 

# limit size to maximum 1000 pixels in width

Set Variable [ $scale ; Value: MBS("GMImage.Scale";$Image; "1000>") ] 

# remove metadata

Set Variable [ $r ; Value: MBS( "GMImage.SetProfile"; $image; "IPTC"; "" ) ] 

Set Variable [ $r ; Value: MBS( "GMImage.SetProfile"; $image; "EXIF"; "" ) ] 

Set Variable [ $r ; Value: MBS( "GMImage.SetProfile"; $image; "XMP"; "" ) ] 

# save

Set Variable [ $NewImage ; Value: MBS("GMImage.WriteToJPEGContainer"; $Image) ] 

If [ MBS("IsError") = 0 ] 

Set Field [ Get Preview::Preview ; $NewImage ] 

Set Field [ Get Preview::Made using ; "GraphicsMagick" ] 

Set Variable [ $r ; Value: MBS("GMimage.Release";$Image) ] 

Exit Script [ Text Result:    ] 

End If

Set Variable [ $r ; Value: MBS("GMimage.Release";$Image) ] 

End If

 

As you see we load an image from a container field or a variable with a container value. Then we scale it to a maximum width of 1000 pixels. We remvoe metadata and then write out a JPEG image.

We could add a call to GMImage.SetDensity in order to change resolution metadata if needed.

15 04 23 - 10:49

Start Chat