« MBS Xojo Plugins, ver… | Home | Physics example for S… »

Convert a SVG image to PNG with alpha channel

You can use GraphicsMagick functions in MBS FileMaker Plugin to convert a SVG to a PNG image with transparency.

To assist there we add a new GMImage.ReadFromContainer function to our plugin. This allows you to create the picture, configure it and then load the picture into the image. When you set background to transparent in a picture with alpha channel, you can preserve the transparency from the SVG. And as you specify a size for the picture and reading it, you can scale the SVG to the size you need:

 

# Load image from container

Set Variable [ $image ; Value: MBS( "GMImage.New"; "500x500"; "transparent" ) ] 

 

# turn on alpha channel and set background to transparent

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

Set Variable [ $r ; Value: MBS( "GMImage.SetBackgroundColor"; $Image; "transparent" ) ] 

 

# Read SVG

Set Variable [ $r ; Value: MBS( "GMImage.ReadFromContainer"; $image; SVG to PNG::InputFile; "500x500"; 0; "SVG" ) ] 

# Output to container and release image

Set Field [ SVG to PNG::OutputFile ; MBS( "GMImage.WriteToPNGContainer"; $image; "test.png") ] 

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

If you have questions or need a newer plugin including the new plugin, please don't hesitate to contact us.

07 04 20 - 12:10