Automating Cumulus (AKA: PHP, VB, COM, Java, etc.)
I'm currently watching a script run through over 1,000 hi-res EPS images and convert those images to JPEGs in three different sizes onto a Windows share running on an AS/400 (aka iSeries). I thought it might be useful to jot down some notes on how I got to this finish line of sorts. The Challenge
A digital asset management system (DAM), Canto's Cumulus Enterprise 5.5, is now being used to catalog all our images. We have a new e-Catalog in development that needs all the related part shots in JPEG format in three different sizes: maximum widths of 90, 180 and 360 pixels. The JPEGs need to be renamed to the corresponding part number, which is stored in a Cumulus field. The e-Catalog is hosted on an AS/400 and therefore the JPEG images need to be accessible to the e-Catalog. New catalog images in the DAM need to be converted and placed on the share every night.

The Solution
Cumulus Enterprise has an API in three different languages/environments: AppleScript, OLE and Java. The script I would write had to run on Windows so that left me with OLE and Java. The Java API is only available if you are a part of Canto's developer program, which there is a yearly fee for. I didn't want to pay money for an API, but the Java API is the only available API that doesn't require that the Cumulus Enterprise client be installed on the server. Canto may still get me the Java API free of charge because they ran me in circles trying to find an appropriate solution to write the script I needed. But, for now, I decided to use the OLE API since I was able to convince the server admin to install the Cumulus client on the server.

The OLE API is documented so-so. There are numerous examples of how you can use the OLE API to solve a variety of common tasks that can be automated. There is also a Windows help file with all the objects and methods defined fairly clearly. What is not so clear from the documentation is how you do something in the context of a command line program. All the examples use a Visual Basic GUI that assumes the client is running. While this makes sense if you're writing scripts that need to interact with the user, it's not very helpful for the times where you need a scheduled script to run via the command line. Between the help file and the examples I was able to put together the code in VB6 to connect to the server, select the catalog I need and run a query against the database. I also had a loop that ran through each found record and exported the corresponding image. Cool!

This solves the first part of the project of getting the records and exporting the images with the ability to name the resulting JPEGs with the corresponding part number. What remains is the ability to convert the images from hi-res EPS files to low-res JPEGs in three different sizes. I thought of using Cumulus' built-in conversion modules but I didn't see a way to define the sizes down to the pixel level, only by percentage. I then quickly turned to my days of web programming and thought of ImageMagick. I never used ImageMagick but I remember reading a bit about it when I was doing a lot of PHP work. It sounded very powerful so I went to the web site and checked it out.

There were two hold ups with ImageMagick: It didn't appear to support conversion of EPS files and the API's were at all different levels of support. The first problem of not being able to convert EPS files was solved when I read that all you needed was an install of Ghostscript. The second problem wasn't as bad as I originally thought. Since I was using VB for the script (or so I thought), the COM object ImageMagick came with was current and had just enough documentation to get it working. So I installed both ImageMagick and Ghostscript on my computer and added the ImageMagick code to my VB script. It worked!

I was psyched but then my hate for VB began to raise its ugly head. I needed to start logging things, sending emails on errors and confirmations that the job ran, manipulating files and catching errors. I admit my VB skills aren't up to par with my Java and PHP skills. VB could easily do what I needed it to do, but then I didn't want to mess with registering DLL files for COM objects I needed and creating a new executable any time I needed the production script to change. In other words, I wanted more of a scripting language that I knew, was capable of doing what I needed it to do and didn't require compilation of any sort. That led me to PHP. If I knew Perl, Python or Ruby, one of those might have done the trick just as well.

The trick with PHP was being able to call the Cumulus API via PHP's COM module. I was skeptical as I heard PHP's COM support was shaky, but I gave it a try. I grabbed my VB6 code and in about 10 minutes had it working in PHP! Is it weird to be using PHP on Windows to run batch jobs? Yes. Do I care? No.

Anyway, I began writing the final part of the script and ran into an issue with ImageMagick. ImageMagick support for PHP on Windows is not well supported. I spent hours trying to get the ImageMagick extension (DLL on Windows) working on my installation of both PHP 4.3 and 4.3.2 — no luck. I then went back to the trusty old exec command that allows you to call an external program from PHP. Sure enough, that did the trick. I was afraid I wouldn't be able to catch errors from the ImageMagick calls that way, but I found that I could. I also thought I might run into problems similar to those I saw when I tried calling an external program from Java, but PHP doesn't have the whole JVM/threaded madness going on so it was a non-issue.

Now I'm just enhancing the code to be more flexible, rather than just work for this one particular task. I'm pretty happy with the results. If I had more time I would have liked to maybe write the script in Python. I may still end up doing that just to get my feet wet with Python. It might be a decent little script to learn a different language with.

If you'd like the PHP code just shoot me a quick message or comment on the site and I'll get it to you.
Posted on 07/18/03 - Category: Technology

Track Backs
No trackbacks for this item. Use this trackback url to ping. (right-click, copy link target)

Referrers




Whispers...

No whispers yet

Whisper (The Colonel is listening)...

:

:
:

The Colonel