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

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