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 » 2008-11-05T08:20:25-07:00

Hello,

is it currently possible to use MSL through MagickWand API?
Mikko Koppanen
My blog: http://valokuva.org

User avatar
magick
Site Admin
Posts: 11015
Joined: 2003-05-31T11:32:55-07:00

Re: MSL through MagickWand API

Post by magick » 2008-11-05T09:00:59-07:00

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 » 2008-11-05T10:36:12-07:00

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: 11015
Joined: 2003-05-31T11:32:55-07:00

Re: MSL through MagickWand API

Post by magick » 2008-11-05T13:00:08-07:00

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 » 2008-11-05T14:57:56-07:00

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: 11015
Joined: 2003-05-31T11:32:55-07:00

Re: MSL through MagickWand API

Post by magick » 2008-11-05T18:28:42-07:00

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 » 2008-11-05T18:50:46-07:00

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: 11015
Joined: 2003-05-31T11:32:55-07:00

Re: MSL through MagickWand API

Post by magick » 2008-11-05T19:21:23-07:00

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 » 2008-11-06T03:32:14-07:00

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 » 2011-03-13T16:19:46-07:00

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 » 2011-03-13T17:28:11-07:00

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