MSL through MagickWand API

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
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

MSL through MagickWand API

Post by mkoppanen »

Hello,

is it currently possible to use MSL through MagickWand API?
Mikko Koppanen
My blog: http://valokuva.org
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MSL through MagickWand API

Post by magick »

Sure, just add your MSL to a file and use MagickReadImage() to read it. You can set MSL properties with MagickSetOption().
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: MSL through MagickWand API

Post by mkoppanen »

magick wrote:Sure, just add your MSL to a file and use MagickReadImage() to read it. You can set MSL properties with MagickSetOption().
Hi,

this is excellent. Is it possible to evaluate the generated MSL using MagickWand API or do I need to use the conjure command line utility?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MSL through MagickWand API

Post by magick »

No you do not need the conjure utility. We were smart enough in the design to make MSL a coder which means it can be interpreted by any ImageMagick read method.
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: MSL through MagickWand API

Post by mkoppanen »

magick wrote:No you do not need the conjure utility. We were smart enough in the design to make MSL a coder which means it can be interpreted by any ImageMagick read method.

msl.c:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <wand/MagickWand.h>

int main()
{
        MagickWand *wand = NewMagickWand();

        if (!MagickReadImage(wand, "msl:t.msl")) {
                printf("Failed to read the image\n");
        }

        printf("Format: %s\n", MagickGetImageFormat(wand));

        wand = DestroyMagickWand(wand);

        return 0;

}
t.msl:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<image size="400x400">
    <read filename="image.gif" />
    <get width="base-width" height="base-height" />
    <resize geometry="%[dimensions]" />
    <get width="width" height="height" />
    <print output="Image sized from %[base-width]x%[base-height] to %[width]x%[height].\n" />
    <write filename="image.png" />
</image>
Am I missing something here? When I compile and run the program it runs without any output. Thanks for the assistance!
Mikko Koppanen
My blog: http://valokuva.org
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MSL through MagickWand API

Post by magick »

Works for us-- of course. We're using ImageMagick 6.4.5-4. You need to set the dimensions property to set the resize size. Here's our results:
  • -> wand
    Image sized from 640x480 to 640x480.
    Format: MSL
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: MSL through MagickWand API

Post by el_supremo »

Just out of curiosity, should there be a valid image in the wand after MagickReadImage has read the MSL file?
I added this after the printf:

Code: Select all

	MagickWriteImage(wand,"msl_out.png");
and when I identify that file I get:

Code: Select all

identify.EXE: Image width or height is zero in IHDR `msl_out.png'.
identify.EXE: Corrupt image `msl_out.png'.
The image file written from within the MSL script is correct.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MSL through MagickWand API

Post by magick »

An empty image container is returned when MSL is interpreted. We have a patch to return a black canvas so it can write a proper image format.
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: MSL through MagickWand API

Post by mkoppanen »

I figured out my problem. My MSL file had one space before the <?xml declaration so the whole operation died silently.

Thanks for the assistance guys!
Mikko Koppanen
My blog: http://valokuva.org
amol
Posts: 1
Joined: 2011-03-13T15:15:35-07:00
Authentication code: 8675308

Re: MSL through MagickWand API

Post by amol »

Hi,

I'm new to IM and trying to do something very similar. I tried to run the example above. However, I'm not sure how and where to set the input dimensions.

What I'd ultimately like to do is to initialize the variables used in an MSL dynamically in my C/C++ program, then call the MagickWand APIs to read the MSL and execute it.

Using the above MSL as an example, I'd like to do something like this:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <wand/MagickWand.h>


int main()
{
         char *dimensions = getDimensions(); //dynamically get the 'dimension' variable used in t.msl

        MagickWand *wand = NewMagickWand();

        if (!MagickReadImage(wand, "msl:t.msl")) {
		   printf("Failed to read the image\n");
        }

        printf("Format: %s\n", MagickGetImageFormat(wand));

        wand = DestroyMagickWand(wand);
		return 0;
}
Alternately, is it possible to store the variable in a file and have MagickWand pick it up from there and pass it to the MSL?

Thanks!
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: MSL through MagickWand API

Post by el_supremo »

You can set the dimensions by inserting this statement before the MagickReadImage:

Code: Select all

MagickSetOption(wand,"dimensions","320x240");
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
Post Reply