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

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