Page 1 of 1
MSL through MagickWand API
Posted: 2008-11-05T08:20:25-07:00
by mkoppanen
Hello,
is it currently possible to use MSL through MagickWand API?
Re: MSL through MagickWand API
Posted: 2008-11-05T09:00:59-07:00
by magick
Sure, just add your MSL to a file and use MagickReadImage() to read it. You can set MSL properties with MagickSetOption().
Re: MSL through MagickWand API
Posted: 2008-11-05T10:36:12-07:00
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?
Re: MSL through MagickWand API
Posted: 2008-11-05T13:00:08-07:00
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.
Re: MSL through MagickWand API
Posted: 2008-11-05T14:57:56-07:00
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!
Re: MSL through MagickWand API
Posted: 2008-11-05T18:28:42-07:00
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
Re: MSL through MagickWand API
Posted: 2008-11-05T18:50:46-07:00
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
Re: MSL through MagickWand API
Posted: 2008-11-05T19:21:23-07:00
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.
Re: MSL through MagickWand API
Posted: 2008-11-06T03:32:14-07:00
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!
Re: MSL through MagickWand API
Posted: 2011-03-13T16:19:46-07:00
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!
Re: MSL through MagickWand API
Posted: 2011-03-13T17:28:11-07:00
by el_supremo
You can set the dimensions by inserting this statement before the MagickReadImage:
Code: Select all
MagickSetOption(wand,"dimensions","320x240");
Pete