Re: C code for command CONVERT
Posted: 2009-12-04T00:51:36-07:00
please can you tell me the differences?So i can learn...
thank
thank
Use https://github.com/ImageMagick/ImageMagick/discussions instead.
https://imagemagick.com/discourse-server/
https://imagemagick.com/discourse-server/viewtopic.php?t=15115
Code: Select all
//*** Don't need these if ThrowWandException isn't defined
// #include <stdio.h>
// #include <stdlib.h>
// #include <iostream>
#include <windows.h>
#include "wand/magick_wand.h"
//*** I'm using C so I don't need this
// 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); \
//}
//*** The name DrawText conflicts with a Windows function of that name
void u_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;
//*** C requires these two to be in the declaration header
char * utente = "Utente";
char * ID = "ID";
magick_wand = NewMagickWand();
d_wand = NewDrawingWand();
p_wand = NewPixelWand();
// initialize MagickWand environment
MagickWandGenesis();
// Read the image. Change "logo:" to the name of your input image file
status = MagickReadImage(magick_wand,"logo:");
//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,"logo_problem_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();
}
//*** This just makes it work with my testing program
// void main() {
void test_wand(LPTSTR lpCmdLine)
{
char * nome_conferenza = "Conferenza Prova";
char * data = "2/12/2009 17:03";
char * nome_utente = "cane";
char * ID_utente = "3";
u_DrawText(nome_conferenza, data, nome_utente, ID_utente);
//*** I don't need this
// system ("Pause");
}
Code: Select all
identify -list font
Code: Select all
asterisk: wand/drawing-wand.c:770: DrawAnnotation: Assertion `text != (const unsigned char *) ((void *)0)' failed.