Wand ConvertImageCommand not thread safe

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
RobertAnthony

Wand ConvertImageCommand not thread safe

Post by RobertAnthony »

We are currently testing our application that uses ImageMagick to do text annotations on top of images and are finding issues in multi threaded heavy load stress tests.

In light of practical examples that use convert syntax we decided to build a wrapper on top of ConvertImageCommand. We use the following wrapper code inside of our servlet JNI call:

MagickCoreGenesis(*argv,MagickTrue);
exception=AcquireExceptionInfo();
regard_warnings=MagickFalse;
image_info=CloneImageInfo((ImageInfo *) NULL);

status=ConvertImageCommand(image_info,argc,argv,(char **) NULL,exception);
if ((status == MagickFalse) || (exception->severity != UndefinedException))
{
if ((exception->severity < ErrorException) &&
(regard_warnings == MagickFalse))
status=MagickTrue;
CatchException(exception);
}
image_info=DestroyImageInfo(image_info);
exception=DestroyExceptionInfo(exception);
MagickCoreTerminus();

This code however fails when accessed from multiple threads and there also seems to be a memory leak after each execution.

The convert command we want to execute is:
convert -background none -gravity center -fill black -font Arial -size 170x170 -rotate -5 -stroke none caption:Hello +size background_image.jpg +swap -gravity northwest -geometry +0+0 -composite out.jpg

I noticed that using methods that take explicit magick_wand are thread safe (I tried simple image format conversion) while using ConvertImageCommand crashes Tomcat.

I would appreciate if someone could help us figure out how to either:
1) Make the call to ConvertImageCommand thread safe and without memory leaks
or
2) Use wand API to execute the above convert command in a thread safe manner?

We are running 6.3.6-3 ImageMagick on 64bit linux and latest version of Tomcat.

Any help would be most appreciated.
Regards,
-Robert
Post Reply