Vexing use of caption

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
surnameforename

Vexing use of caption

Post by surnameforename »

Hello all,

Platform: Windows Vista 32 bit
Dev env: Visual Studio Express 2008 C++

I've had an utterly frustrating couple of days trying to get/force ImageMagick to do what I want. A friend of mine is using ImageMagick to create blocks of text from the command line with a command in the following form...

convert.exe -size "640 x 480" -pointsize 48 -channel RGBA -fill red -weight 400 -font C:/Windows/Fonts/SCRIPTBL.TTF -gravity Center -background white caption:"this is the caption text and there really is quite a lot of it" -flatten convert_caption_test_release.png

What he ideally wants is to be able to do this and create an in memory image. So far as I can see this isn't possible with the PHP or C++ interfaces because caption: does a number of clever things, first it will wrap the text and second if an image size is specified but no pointsize it will fit the text to the image. Anyway I spent the last day or so hacking various convert.c files (this confusing because there are at least three of them) I thought I had got it working. But in switching back to Release it all started to go wrong.

Going back to basics to track the problem down I have different behaviour in a clean build of the release and debug version of convert.exe The error is have is that when I run the above command with a debug build of convert.exe it works, but with a release build it doesn't. Instead I get the error...

Magick: no decode delegate for this image format `this is the caption text and there really is quite a lot of it' @ error/constitute.c/ReadImage/532.
Magick: missing an image filename `convert_caption_test_release.png' @ error/convert.c/ConvertImageCommand/2953.

I get this running it from the command line or by setting the debug command within Visual Studio. I first came across it when switching back to release from debug build having setup the argv array in code.

I'm sure this was working in Release yesterday, I've tried lots of different ways of adding quotes etc. But it works in debug!

Any ideas, this is sending me crazy,

G
surnameforename

Re: Vexing use of caption

Post by surnameforename »

Forgot to say I'm building 6.6.3.

For the test I left the configure options at their defaults except for build all of the tests, examples etc.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Vexing use of caption

Post by el_supremo »

I don't know why you're having problems with release vs. debug builds. Your command works for me with a source build of IM 6.6.3-9 on WinXP.

I've written a C function which does most of your convert command. It shouldn't be difficult to translate this to C++/PHP.

Pete

Code: Select all

#include <windows.h>
#include <wand/magick_wand.h>
// include malloc for the Import/ExportPixels
#include <malloc.h>
void test_wand(LPTSTR lpCmdLine)
{
    MagickWand *mw = NULL;
    size_t width,height;
    int export=0;

    MagickWandGenesis();
    mw = NewMagickWand();

    MagickSetSize(mw,640,0);
    MagickSetPointsize(mw,48);
    MagickSetFont(mw,"Lucida-Handwriting-Italic");
    MagickSetOption(mw,"fill","red");
    MagickSetOption(mw,"background","white");
    MagickSetGravity(mw,CenterGravity);
    MagickReadImage(mw,"caption:this is the caption text and there really is quite a lot of it");
    if(!export) {    
        MagickWriteImage(mw,"caption2.gif");
    } else {
        // Export the pixels to a Buffer in memory
        // This just exports as 8-bit RGB  
        unsigned char *Buffer = NULL;
        width = MagickGetImageWidth(mw);
        height = MagickGetImageHeight(mw);
        Buffer = malloc(3*width*height);
        // Export the whole image
        MagickExportImagePixels(mw,0,0,width,height,"RGB",CharPixel,Buffer);
        // Mangle the buffer any way you like here
        // ......
        // If you need the mangled image back in a wand
        //MagickImportImagePixels(mw,0,0,width,height,"RGB",CharPixel,Buffer);
        free(Buffer);
    }
    if(mw)DestroyMagickWand(mw);
}
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