C code for command CONVERT

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?".
erotavlas_turbo

C code for command CONVERT

Post by erotavlas_turbo »

Hi all,

I'm a new user of Imagemagick, it's great work! I have tried the convert command and i would like to write a c/c++ code that replicate its function. I'm not good programmer...Exist this code?or i must write it?

Thank you very much


PS
I would like realize something like this

Code: Select all

convert -font helvetica -fill black -pointsize 30 -draw 'text 18,30 "Text"' -font helvetica -pointsize 18 -fill yellow -draw 'text 30,90 "Text"' -draw 'text 180,90 "Text"' img.jpg img.png 
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: C code for command CONVERT

Post by el_supremo »

This C function does what you want (I used the MS compiler for Windows). Just change the name of the input and output files, and the text strings to suit you. You can also change the font name, size and colour.
For more examples of C functions see the link in my signature - there are some more examples of playing with text.

Pete

Code: Select all

#include <windows.h>
#include <wand/magick_wand.h>
void test_wand(LPTSTR lpCmdLine)
{
	MagickWand *magick_wand = NULL;
	DrawingWand *d_wand = NULL;
	PixelWand *p_wand = NULL;

	magick_wand = NewMagickWand();
	d_wand = NewDrawingWand();
	p_wand = NewPixelWand();


	// Read the image. Change "logo:" to the name of your input image file
	MagickReadImage(magick_wand,"logo:");

	// Set up the font size and colour
	DrawSetFont(d_wand,"Helvetica");
	PixelSetColor(p_wand,"black");
	DrawSetFillColor(d_wand,p_wand);
	DrawSetFontSize(d_wand,30);
	// Now draw the text
	DrawAnnotation(d_wand,18,30,"Put your text here");

	// same font - different colour and size
	PixelSetColor(p_wand,"yellow");
	DrawSetFillColor(d_wand,p_wand);
	DrawSetFontSize(d_wand,18);
	// Now draw the text
	DrawAnnotation(d_wand,30,90,"Put more text here");

	// same font, size and colour
	DrawAnnotation(d_wand,180,90,"Put the third text here");

	// Draw the image on to the magick_wand
	MagickDrawImage(magick_wand,d_wand);

	// and write it
	MagickWriteImage(magick_wand,"logo_text.png");

	/* Clean up */
	if(magick_wand)magick_wand = DestroyMagickWand(magick_wand);
	if(d_wand)d_wand = DestroyDrawingWand(d_wand);
	if(p_wand)p_wand = DestroyPixelWand(p_wand);

}
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.
erotavlas_turbo

Re: C code for command CONVERT

Post by erotavlas_turbo »

Thank you very much for your fast response!!!

I have two question:

1)the example that you have posted not work i get the following error...

Code: Select all

: error C2664: 'MagickDrawAnnotation': unable to convert 4 parameter from 'const char [19]' to 'const unsigned char *'. 
http://msdn.microsoft.com/en-us/library/s5b150wd%28VS.71%29.aspx
2)is there the possibility to call your example and pass to it the parameters as font size, color, ... and the text to write?for instance if i have these parameters in program and call your examples...

DrawAnnotation(d_wand,30,90,"Put more text here");

Can i substitute "Put more text here" with a generic char variable?

3)i would like to use it in linux, what modify must i do?

Thank for help
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: C code for command CONVERT

Post by el_supremo »

DrawAnnotation(d_wand,30,90,"Put more text here");

Can i substitute "Put more text here" with a generic char variable?
Yes. And that might solve your problem 1 as well.
3)i would like to use it in linux, what modify must i do?
- remove the first line - you won't need to include windows.h
- change the function definition to:
void test_wand(void)

It should then compile under Linux.

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.
erotavlas_turbo

Re: C code for command CONVERT

Post by erotavlas_turbo »

Hi,

I can't compile your example program under windows and linux...the errors are different. For example in windows with visual studio 2008 i have followed this post viewtopic.php?f=6&t=11757, but i get linker error...
If i try to compile your resize.c i get the following compilation errors

Code: Select all

17 void main(void)
{
	MagickWand *m_wand = NULL;
	
	int width,height;
	
	MagickWandGenesis();
	
	m_wand = NewMagickWand();
	// Read the image - all you need to do is change "logo:" to some other
	// filename to have this resize and, if necessary, convert a different file
	MagickReadImage(m_wand,"logo:");
	
	// Get the image's width and height
	width = MagickGetImageWidth(m_wand);
	height = MagickGetImageHeight(m_wand);
	
	// Cut them in half but make sure they don't underflow
	if((width /= 2) < 1)width = 1;
	if((height /= 2) < 1)height = 1;
	
	// Resize the image using the Lanczos filter
	// The blur factor is a "double", where > 1 is blurry, < 1 is sharp
	// I haven't figured out how you would change the blur parameter of MagickResizeImage
	// on the command line so I have set it to its default of one.
	MagickResizeImage(m_wand,width,height,LanczosFilter,1);
	
	// Set the compression quality to 95 (high quality = low compression)
	MagickSetImageCompressionQuality(m_wand,95);
	
	/* Write the new image */
	MagickWriteImage(m_wand,"logo_resize.jpg");
	
	/* Clean up */
	if(m_wand)m_wand = DestroyMagickWand(m_wand);
	
	MagickWandTerminus();
54}

Code: Select all

23 error C3861: 'MagickWandGenesis': identifier not found
45 error C3861: 'MagickSetImageCompressionQuality': identifier not found
51 error C2440: '=': unable to convert from 'unsigned int' to 'MagickWand *'
53 error C3861: 'MagickWandTerminus': identifier not found
other errors appear with your code in previous post.

Code: Select all

   /* Clean up */
59   if(magick_wand)magick_wand = DestroyMagickWand(magick_wand);
60   if(d_wand)d_wand = DestroyDrawingWand(d_wand);
61   if(p_wand)p_wand = DestroyPixelWand(p_wand);

Code: Select all

59 error C2440: '=': unable to convert from 'unsigned int' to 'MagickWand *'
60 error C2440: '=': unable to convert from  'void' to 'DrawingWand *'
61 error C2440: '=': unable to convert from  'void' to 'PixelWand *'

thank you
erotavlas_turbo

Re: C code for command CONVERT

Post by erotavlas_turbo »

Hi,

after multiple trials i have resolved the windows compiling problem. :D The image magick libraries are too old... :(

Under linux the problem is still there...
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: C code for command CONVERT

Post by el_supremo »

Which version of IM are you using with Linux and what is the command you are using to compile and link the code?

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.
erotavlas_turbo

Re: C code for command CONVERT

Post by erotavlas_turbo »

The version of IM is the same under linux and windows 6.5.8.0. The command line is the following

Code: Select all

gcc -o main main.c 
/tmp/cc8CgSgC.o: In function `main':
main.c:(.text+0x22): undefined reference to `NewMagickWand'
main.c:(.text+0x2b): undefined reference to `NewDrawingWand'
main.c:(.text+0x34): undefined reference to `NewPixelWand'
main.c:(.text+0x4c): undefined reference to `MagickReadImage'
main.c:(.text+0x60): undefined reference to `DrawSetFont'
main.c:(.text+0x74): undefined reference to `PixelSetColor'
main.c:(.text+0x88): undefined reference to `DrawSetFillColor'
main.c:(.text+0x9e): undefined reference to `DrawSetFontSize'
main.c:(.text+0xc7): undefined reference to `DrawAnnotation'
main.c:(.text+0xdb): undefined reference to `PixelSetColor'
main.c:(.text+0xef): undefined reference to `DrawSetFillColor'
main.c:(.text+0x105): undefined reference to `DrawSetFontSize'
main.c:(.text+0x12e): undefined reference to `DrawAnnotation'
main.c:(.text+0x157): undefined reference to `DrawAnnotation'
main.c:(.text+0x16b): undefined reference to `MagickDrawImage'
main.c:(.text+0x17f): undefined reference to `MagickWriteImage'
main.c:(.text+0x192): undefined reference to `DestroyMagickWand'
main.c:(.text+0x1a9): undefined reference to `DestroyDrawingWand'
main.c:(.text+0x1c0): undefined reference to `DestroyPixelWand'
collect2: ld returned 1 exit status
where main.c is your code...

under windows the compilation is ok, but the result no...
With Visual Studio 2008 i have a command line application and i get the following information

Code: Select all

Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghostscript_font_path@n019003l.pfb' @ annota
te.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g180x60  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-sTFbN8b5" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-X74jPGof" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-I4nrEl7D" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g180x60  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-sTFbN8b5" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-X74jPGof" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-I4nrEl7D" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-D7UVn5so': No such file or directory @ p
s.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghostscript_font_path@n019003l.pfb' @ annota
te.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g180x60  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-_ZKDQcrG" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-nBC_4f74" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-H5EKqY_n" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g180x60  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-_ZKDQcrG" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-nBC_4f74" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-H5EKqY_n" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-KWtpj1R_': No such file or directory @ p
s.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghostscript_font_path@n019003l.pfb' @ annota
te.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g108x36  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-J1vx4S5z" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-Yajb3x4u" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-R78Q6CaA" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g108x36  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-J1vx4S5z" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-Yajb3x4u" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-R78Q6CaA" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-MdWDXMRO': No such file or directory @ p
s.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghostscript_font_path@n019003l.pfb' @ annota
te.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g108x36  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-5xjYtRCS" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-3-J_3kkh" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-HVYFNTmz" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g108x36  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-5xjYtRCS" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-3-J_3kkh" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-HVYFNTmz" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-mRbK1BC5': No such file or directory @ p
s.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghostscript_font_path@n019003l.pfb' @ annota
te.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g108x36  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-yGgYP7_b" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-3ZwB9xqv" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-uw0a-BIi" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g108x36  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-yGgYP7_b" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-3ZwB9xqv" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-uw0a-BIi" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-GSa6fGZW': No such file or directory @ p
s.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghostscript_font_path@n019003l.pfb' @ annota
te.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g108x36  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-FkL4K_LY" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-WtS-p3T-" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-1Y07lwMp" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop
-dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g108x36  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-FkL4K_LY" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick-WtS-p3T-" "-fC:
/Users/ADMINI~1/AppData/Local/Temp/magick-1Y07lwMp" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-VoX1SeXP': No such file or directory @ p
s.c/ReadPSImage/765.
Premere un tasto per continuare . . . 
thank
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: C code for command CONVERT

Post by el_supremo »

I haven't compiled programs with Linux but Magick says that this is the standard way to compile a MagickWand program:

Code: Select all

gcc `MagickWand-config --cflags --cppflags` -o main main.c `MagickWand-config --ldflags --libs`
The problem with the windows program appears to be that ghostscript can't find the font(s) it is looking for. Make sure that the font name you are using actually exists on your system.

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.
erotavlas_turbo

Re: C code for command CONVERT

Post by erotavlas_turbo »

Hi,

in windows i have finally resolved. I must change your code as follow

void DrawText(char * nome_conferenza, char * data, char * nome_utente, char * ID_utente) {

MagickBooleanType status;
MagickWand *magick_wand = NULL;
DrawingWand *d_wand = NULL;
PixelWand *p_wand = NULL;

magick_wand = NewMagickWand();
d_wand = NewDrawingWand();
p_wand = NewPixelWand();

char * utente = "Utente";
char * ID = "ID";

// initialize MagickWand environment
MagickWandGenesis();

// Read the image. Change "logo:" to the name of your input image file
status = MagickReadImage(magick_wand,"Asterisk_logo.jpg");
if (status == MagickFalse)

// Set up the font size and colour
DrawSetFont(d_wand,"Helvetica");
PixelSetColor(p_wand,"black");
DrawSetFillColor(d_wand,p_wand);
DrawSetFontSize(d_wand,28);
// Now draw the text
DrawAnnotation(d_wand,10,50,(const unsigned char *) titolo);

DrawSetFontSize(d_wand,14);
DrawAnnotation(d_wand,150,15,(const unsigned char *) data);
// same font - different colour and size
PixelSetColor(p_wand,"yellow");
DrawSetFillColor(d_wand,p_wand);
DrawSetFontSize(d_wand,20);
// Now draw the text
DrawAnnotation(d_wand,30,90,(const unsigned char *) utente);

// same font, size and colour
DrawAnnotation(d_wand,180,90,(const unsigned char *) ID);

// Draw the image on to the magick_wand
MagickDrawImage(magick_wand,d_wand);

// and write it
status = MagickWriteImage(magick_wand,"campione_text.jpg");

/* Clean up */
if (status == MagickFalse)
// ThrowWandException(magick_wand);
if(magick_wand) magick_wand = DestroyMagickWand(magick_wand);
if(d_wand) d_wand = DestroyDrawingWand(d_wand);
if(p_wand) p_wand = DestroyPixelWand(p_wand);

// terminate the MagickWand environment
MagickWandTerminus();
}
I think that the problem is in variable MagickBooleanType status and in the control IF

Code: Select all

if (status == MagickFalse)
I don't know why... :shock:, but i'm happy!!!

in linux with your tip the code compile without error but i can't find the result. Is there a different path respect to windows?How can i pass the input image and get the output image?

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

Re: C code for command CONVERT

Post by el_supremo »

There are two errors in your code.

Code: Select all

status = MagickReadImage(magick_wand,"Asterisk_logo.jpg");
if (status == MagickFalse)

// Set up the font size and colour
DrawSetFont(d_wand,"Helvetica");
The "if" statement is not doing anything useful and in fact, worse yet, it changes your code in a way you don't want. That code is equivalent to this:

Code: Select all

status = MagickReadImage(magick_wand,"Asterisk_logo.jpg");
if (status == MagickFalse) DrawSetFont(d_wand,"Helvetica");
This will only set the font if the MagickReadImage fails.

You have the same kind of problem near the end of your code:

Code: Select all

/* Clean up */
if (status == MagickFalse)
// ThrowWandException(magick_wand);
if(magick_wand) magick_wand = DestroyMagickWand(magick_wand);
This is equivalent to:

Code: Select all

/* Clean up */
if (status == MagickFalse)  if(magick_wand) magick_wand = DestroyMagickWand(magick_wand);
In this case you will only Destroy magick_wand if the MagickWrite statement fails. This will produce a memory leak because when the write succeeds the memory associated with magick_wand is not released.

When you comment out any part of an if statement you must make sure that it still does what you want. In these two cases when you comment out part of the if statement you must do the same to all of it.

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.
erotavlas_turbo

Re: C code for command CONVERT

Post by erotavlas_turbo »

you are right but with this part of code works. If i try to comment this i get the previous message and the result is not good. It's strange...
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: C code for command CONVERT

Post by el_supremo »

Just to be sure we're talking about the same thing:
change this:

Code: Select all

status = MagickReadImage(magick_wand,"Asterisk_logo.jpg");
if (status == MagickFalse)

// Set up the font size and colour
DrawSetFont(d_wand,"Helvetica");
to this:

Code: Select all

status = MagickReadImage(magick_wand,"Asterisk_logo.jpg");

// Set up the font size and colour
DrawSetFont(d_wand,"Helvetica");
and change this:

Code: Select all

/* Clean up */
if (status == MagickFalse)
// ThrowWandException(magick_wand);
if(magick_wand) magick_wand = DestroyMagickWand(magick_wand);
to this:

Code: Select all

/* Clean up */
if(magick_wand) magick_wand = DestroyMagickWand(magick_wand);
Does that work on Windows?

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.
erotavlas_turbo

Re: C code for command CONVERT

Post by erotavlas_turbo »

Of course!!! If i comment the first "if"

Code: Select all

// Read the image. Change "logo:" to the name of your input image file
status = MagickReadImage(magick_wand,"Asterisk_logo.jpg");
if (status == MagickFalse)
//ThrowWandException(magick_wand);
the second "if" is not a problem...

This is my console information.

Code: Select all

Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghos
tscript_font_path@n019003l.pfb' @ annotate.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g504x56  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-_U9uGK1A" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-gOHS4A_y" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-Ax9ZI3Db" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g504x56  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-_U9uGK1A" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-gOHS4A_y" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-Ax9ZI3Db" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-
SOUE92Vf': No such file or directory @ ps.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghos
tscript_font_path@n019003l.pfb' @ annotate.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g504x56  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-FbSZKyMq" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-Gnd2D6Yq" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-5WTONKYu" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g504x56  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-FbSZKyMq" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-Gnd2D6Yq" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-5WTONKYu" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-
JvN9N2gc': No such file or directory @ ps.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghos
tscript_font_path@n019003l.pfb' @ annotate.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g238x28  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-2Miz9kAm" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-HRx4bqQT" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-QSalWIb8" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g238x28  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-2Miz9kAm" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-HRx4bqQT" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-QSalWIb8" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-
tb1qMA8g': No such file or directory @ ps.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghos
tscript_font_path@n019003l.pfb' @ annotate.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g238x28  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-FeB86aNr" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-HmN7-OlD" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-mRm8neL_" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g238x28  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-FeB86aNr" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-HmN7-OlD" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-mRm8neL_" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-
bn82zEVq': No such file or directory @ ps.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghos
tscript_font_path@n019003l.pfb' @ annotate.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g160x40  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-1GE9y75e" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-1uwIiJnD" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-eHRXP-r2" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g160x40  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-1GE9y75e" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-1uwIiJnD" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-eHRXP-r2" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-
IImK02NO': No such file or directory @ ps.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghos
tscript_font_path@n019003l.pfb' @ annotate.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g160x40  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-6I4Gg4AB" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-cJgXFm_J" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-B5qfTMHQ" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g160x40  "-sOutputF
ile=C:/Users/ADMINI~1/AppData/Local/Temp/magick-6I4Gg4AB" "-fC:/Users/ADMINI~1/A
ppData/Local/Temp/magick-cJgXFm_J" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magic
k-B5qfTMHQ" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-
kvpX99xU': No such file or directory @ ps.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghos
tscript_font_path@n019003l.pfb' @ annotate.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g80x40  "-sOutputFi
le=C:/Users/ADMINI~1/AppData/Local/Temp/magick-M-CakD2-" "-fC:/Users/ADMINI~1/Ap
pData/Local/Temp/magick-jF9POr32" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick
-yzJKhSsR" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g80x40  "-sOutputFi
le=C:/Users/ADMINI~1/AppData/Local/Temp/magick-M-CakD2-" "-fC:/Users/ADMINI~1/Ap
pData/Local/Temp/magick-jF9POr32" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick
-yzJKhSsR" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-
53mMqE_u': No such file or directory @ ps.c/ReadPSImage/765.
Magick: unable to read font `C:\Program Files\ImageMagick-6.5.8-Q16\config\@ghos
tscript_font_path@n019003l.pfb' @ annotate.c/RenderFreetype/1043.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g80x40  "-sOutputFi
le=C:/Users/ADMINI~1/AppData/Local/Temp/magick-16335d4v" "-fC:/Users/ADMINI~1/Ap
pData/Local/Temp/magick-Ow4ChBgd" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick
-VbR_WdXV" @ utility.c/SystemCommand/1964.
Magick: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dN
OPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVIC
E=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g80x40  "-sOutputFi
le=C:/Users/ADMINI~1/AppData/Local/Temp/magick-16335d4v" "-fC:/Users/ADMINI~1/Ap
pData/Local/Temp/magick-Ow4ChBgd" "-fC:/Users/ADMINI~1/AppData/Local/Temp/magick
-VbR_WdXV" -c showpage @ utility.c/SystemCommand/1964.
Magick: Postscript delegate failed `C:/Users/ADMINI~1/AppData/Local/Temp/magick-
0pvbqvIb': No such file or directory @ ps.c/ReadPSImage/765.
Press a button to continue...
If you don't believe at my word, please try it...

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <iostream>

#include <windows.h>
#include "wand/magick_wand.h"

using namespace std;

//#define ThrowWandException(wand) \
//{ \
//  char \
//    *description; \
// \
//  ExceptionType \
//    severity; \
// \
//  description=MagickGetException(wand,&severity); \
//  (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
//  description=(char *) MagickRelinquishMemory(description); \
//  exit(-1); \
//}


void DrawText(char * nome_conferenza, char * data, char * nome_utente, char * ID_utente) {

	MagickBooleanType status;
    MagickWand *magick_wand = NULL;
    DrawingWand *d_wand = NULL;
    PixelWand *p_wand = NULL;

    magick_wand = NewMagickWand();
    d_wand = NewDrawingWand();
    p_wand = NewPixelWand();

	char * utente = "Utente";
	char * ID = "ID";

	// initialize MagickWand environment
	MagickWandGenesis();
	
    // Read the image. Change "logo:" to the name of your input image file
    status = MagickReadImage(magick_wand,"Asterisk_logo.jpg");
	//if (status == MagickFalse) 
	//ThrowWandException(magick_wand);
    
	// Set up the font size and colour
    DrawSetFont(d_wand,"Helvetica");
    PixelSetColor(p_wand,"black");
    DrawSetFillColor(d_wand,p_wand);
    DrawSetFontSize(d_wand,28);
    // Now draw the text
	DrawAnnotation(d_wand,10,50,(const unsigned char *) nome_conferenza);

	DrawSetFontSize(d_wand,14);
	DrawAnnotation(d_wand,150,15,(const unsigned char *) data);
    // same font - different colour and size
    PixelSetColor(p_wand,"yellow");
    DrawSetFillColor(d_wand,p_wand);
    DrawSetFontSize(d_wand,20);
    // Now draw the text
    DrawAnnotation(d_wand,30,90,(const unsigned char *) utente);

    // same font, size and colour
    DrawAnnotation(d_wand,180,90,(const unsigned char *) ID);

    // Draw the image on to the magick_wand
    MagickDrawImage(magick_wand,d_wand);

    // and write it
    status = MagickWriteImage(magick_wand,"campione_text.jpg");

    /* Clean up */
   // if (status == MagickFalse)
//    ThrowWandException(magick_wand);
    if(magick_wand) magick_wand = DestroyMagickWand(magick_wand);
    if(d_wand) d_wand = DestroyDrawingWand(d_wand);
    if(p_wand) p_wand = DestroyPixelWand(p_wand);
	
	// terminate the MagickWand environment
	MagickWandTerminus();
}


void main() {

		
	char * nome_conferenza = "Conferenza Prova";
	char * data = "2/12/2009 17:03";
	char * nome_utente = "cane";
	char * ID_utente = "3";
	DrawText(nome_conferenza, data, nome_utente, ID_utente);
	system ("Pause");

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

Re: C code for command CONVERT

Post by el_supremo »

I made a couple of minor changes to your code (I use C, not C++) and it works for me.

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