Tech Articles


Using ImageMagick from PowerBuilder


ImageMagick is a free open-source software package that allows you to convert image files between formats, resize images and perform other functions. It can be used from the command line or as a COM object using PowerBuilder’s OLEObject functionality.

 

You can download the installer from here: http://www.imagemagick.org/script/binary-releases.php#windows

 

You must use one of the installers with the word “dynamic” in the description. I chose the Win32 installer because it offers a higher resolution than the Win64 Dynamic installer.

 

The command documentation for ImageMagick can be found here: http://www.imagemagick.org/script/command-line-tools.php

 

There are several commands that are supported by the COM interface.

 

compare: Compares two image files and returns information about the differences.

 

composite: Overlaps one image over another resulting in a third image file.

 

convert: Converts between image formats as well as resizing the image and other actions such as blur, crop, despeckle, and much more.

 

identify: Describes the format and characteristics of image files.

 

mogrify: Resizes the image and other actions such as blur, crop, despeckle, and much more. Mogrify overwrites the original image file, whereas, convert writes to a different image file.

 

montage: Creates a composite image by combining several separate images. The images are tiled on the composite image optionally adorned with a border, frame, image name, and more.

 

Here is an example that converts a JPG file to PNG:

 

OLEObject oMagick

String ls_origfile, ls_destfile

Integer li_rc

Any la_result

 

ls_origfile = “C:\PBSource\PB105\ImageMagick\Totoro.jpg”

ls_destfile = “C:\PBSource\PB105\ImageMagick\Totoro.png”

 

oMagick = Create OLEObject

 

li_rc = oMagick.ConnectToNewObject(“ImageMagickObject.MagickImage”)

If li_rc = 0 Then

   la_result = oMagick.Convert(ls_origfile, “-format”, “png”, ls_destfile)

   MessageBox(“Convert”, “Result: ” + String(la_result))

Else

   MessageBox(“ConnectToNewObject”, “Failed: ” + String(li_rc), StopSign!)

End If

 

oMagick.DisconnectObject()

 

Destroy oMagick

Comments (0)
There are no comments posted here yet

Find Articles by Tag

Android Debugger Open Source Outlook XML PostgreSQL Design PowerBuilder (Appeon) Testing Event Handler Messagging Authentication Array PDFlib UI Modernization CrypterObject OLE Configuration Authorization OrcaScript Icon NativePDF Jenkins Transaction Debugging COM Windows 10 Icons Deployment Service Expression DragDrop Windows OS HTTPClient Oracle Database Table Schema Web API IDE .NET DataStore Export JSON Text UI Themes Database Table Data Stored Procedure 32-bit SQL Window Installation Encryption SDK DataWindow JSON Import JSON Linux OS Database Connection GhostScript TLS/SSL InfoMaker Database Object Web Service Proxy JSONGenerator JSONParser PowerBuilder 64-bit TortoiseGit TreeView SQL Server MessageBox Database Profile PBNI Excel .NET Std Framework Azure C# RESTClient Event Export SOAP PDF Class SnapObjects Charts External Functions Visual Studio PBDOM Application DLL REST PowerScript (PS) API Data Performance RichTextEdit Control Debug Source Control Bug Platform Encoding SVN SqlModelMapper Model Branch & Merge OAuth 2.0 OAuth Resize Trial SqlExecutor iOS ActiveX Validation PowerBuilder Compiler RibbonBar Builder WinAPI Database Painter Sort Automated Testing PBVM Git Script File Variable Repository .NET Assembly UI Elevate Conference Interface ODBC CI/CD Syntax Database DataType DevOps Mobile CoderObject License PFC JSON Graph PowerServer Web Database Table BLOB SnapDevelop Event Handling DataWindow Import TFS RibbonBar Error PostgreSQL ODBC driver Source Code Filter Migration WebBrowser PowerServer Mobile Menu