MSL through MagickWand API
MSL through MagickWand API
Hello,
is it currently possible to use MSL through MagickWand API?
is it currently possible to use MSL through MagickWand API?
Mikko Koppanen
My blog: http://valokuva.org
My blog: http://valokuva.org
Re: MSL through MagickWand API
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
Hi,magick wrote:Sure, just add your MSL to a file and use MagickReadImage() to read it. You can set MSL properties with MagickSetOption().
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
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
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;
}
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>
Mikko Koppanen
My blog: http://valokuva.org
My blog: http://valokuva.org
Re: MSL through MagickWand API
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
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: MSL through MagickWand API
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:
and when I identify that file I get:
The image file written from within the MSL script is correct.
Pete
I added this after the printf:
Code: Select all
MagickWriteImage(wand,"msl_out.png");
Code: Select all
identify.EXE: Image width or height is zero in IHDR `msl_out.png'.
identify.EXE: Corrupt image `msl_out.png'.
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.
See my message in this topic for a link to a zip of all the files.
Re: MSL through MagickWand API
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
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!
Thanks for the assistance guys!
Mikko Koppanen
My blog: http://valokuva.org
My blog: http://valokuva.org
Re: MSL through MagickWand API
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:
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!
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;
}
Thanks!
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: MSL through MagickWand API
You can set the dimensions by inserting this statement before the MagickReadImage:
Pete
Code: Select all
MagickSetOption(wand,"dimensions","320x240");
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.
See my message in this topic for a link to a zip of all the files.