Skip to Content
Author's profile photo Former Member

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


Assigned Tags

      21 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Roland,

      does ImageMagick convert EMF file in PNG or JPG ?

      Thank you

      Best Regards

      Luca Ferrante

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Yes. There are over 100 supported formats:

      http://www.imagemagick.org/script/formats.php

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      It even converts from PDF if you have Ghostscript installed.

      Author's profile photo Former Member
      Former Member

      Ok Roland, thank you very much, it sound good !!

      Author's profile photo Former Member
      Former Member

      Hi all,

      some year ago  i published the following article on ISUG :

      http://www.slideshare.net/marcocimaroli/image-magic-for-powerbuilder

      I can share PB source files.

      Thanks

      Marco

      Author's profile photo Former Member
      Former Member

      Hi all,

      Sounds interesting Marco. Can you share this PBLs ?

      jtagarro  _*at*_  neosistemassrl  _*dot*_ com

      Thanks in advance.

      __________________

      AUS Julián Tagarro

      NeoSistemas SRL

      Author's profile photo Former Member
      Former Member

      Hi Marco.

      I would like to receive the source files too.

      lcgribeiro@gmail.com

      Regards

      Author's profile photo Former Member
      Former Member

      Hi all,

      this is the link to download my source files:

      https://www.dropbox.com/s/jb4fcwc8zmqi73s/PbMagick10ISUG.rar

      Thanks

      Marco

      Author's profile photo Former Member
      Former Member

      Thanks for sharing !!

      Best regards.

      _________________

      AUS Julián Tagarro

      NeoSistemas SRL

      Author's profile photo Former Member
      Former Member

      Hi All,

      This product looks great and has amazing potential.  I am having however a problem using it!

      Roland & Marco, I have installed the latest 32-bit version and registered the ImageMagickObject.dll (ImageMagick-6.8.9-3-Q16-x86-dll).  I can connect to the OLE object, but when I run any of the functions I am getting an "error calling external object function" error.

      What is strange is that the functions still seems to be firing in the background anyway, as when I use the convert Image to resize my images and replicate my images.  New images are being created, but the error keeps coming up each time.

      I am using PB12 Classic

      Any help would be greatly appreciated.

      Michael

      Author's profile photo Former Member
      Former Member

      Roland / Marco,

      I am wondering whether there may be something wrong in the built binary that I have downloaded - released 8th June 2014.

      Could you post a link to the versions of the dll you have used so that I could try the older versions to test for the same problem.

      Many Thanks,

      Michael

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      I have 6.8.8 and the latest is 6.8.9. I don't see where you can download prior version executables.

      If you go to their website and click Download from the left hand nav area, it goes to a page with various mirror websites. Choose one of them and look for ImageMagick-6.8.9-3-Q16-x86-dll.exe.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      I found a place that has old binaries:

      http://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/binaries/

      It goes all the way back to 6.6.5 from 2010.

      Author's profile photo Former Member
      Former Member

      Roland,

      Ran into the same exact issue "error calling external object function" with running ver 6.8.9. Trying to figure out how you installed 6.8.5-9? Was able to download the zip (ImageMagic-6.8.5-9.zip) file from SUNET's Index of /pub/multimedia/graphics/ImageMagick but not able to install this version as there is no install application. Can you please shed some light as to how you installed version 6.8.5-9?

      Thanks in advance.

      Sai.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      They only have installers for the current version. I have ImageMagick-6.8.8-Q8 which was the current version when I downloaded it. Older version are only source code. I could zip up my install folder for you. Then you could unzip it over the version you have.

      Author's profile photo Former Member
      Former Member

      That would be wonderful if it is not too much trouble. Thank you very much again for your reply.

      Author's profile photo Former Member
      Former Member
      Blog Post Author
      Author's profile photo Former Member
      Former Member

      That works! Just replaced the contents of newer version contents with what you sent. Thank you very much again.

      Author's profile photo Former Member
      Former Member

      SUNET's Index of /pub/multimedia/graphics/ImageMagick/binaries is the directory you need to be in to download the installers.  This is where I downloaded the older version.

      You will need to download any of the files listed with 'static' or 'dll' in the name.  These are the exe installers.

      http://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/binaries/ImageMagick-6.8.5-9-Q16-x86-dll.exe

      Above is the link for the 32 bit version.

      Michael

      Author's profile photo Former Member
      Former Member

      Hi Michael,

      i am using 6.8.5 version, it works fine while 6.8.9 seems to have problems.

      I am using Win7 64 bit.

      Marco

      Author's profile photo Former Member
      Former Member

      Roland/Marco,

      Thank you for the assistance.  I now have the code working using version 6.8.5-9.

      I will experiment later with newer versions to try and find where the build error started to arise.

      Regards,

      Michael