Created
May 26, 2014 14:59
-
-
Save sorribas/f3da3f2c8f90f4e2fe9a to your computer and use it in GitHub Desktop.
Magick Wand API example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <wand/magick_wand.h> | |
void read_file(char** contents, int* length) { | |
int size; | |
FILE *input_file = fopen("Eduardo.png", "rb"); | |
fseek(input_file, 0, SEEK_END); | |
size = ftell(input_file); | |
rewind(input_file); | |
*contents = malloc(size * sizeof(char)); | |
fread(*contents, sizeof(char), size, input_file); | |
fclose(input_file); | |
} | |
int main(int argc,char **argv) { | |
MagickWand *magick_wand; | |
MagickPassFail status = MagickPass; | |
const char *infile, *outfile; | |
char* contents; | |
int length; | |
read_file(&contents, &length); | |
if (argc != 3) { | |
fprintf(stderr,"Usage: %s: infile outfile\n",argv[0]); | |
return 1; | |
} | |
infile=argv[1]; | |
outfile=argv[2]; | |
// Initialize GraphicsMagick API | |
InitializeMagick(*argv); | |
// Allocate Wand handle | |
magick_wand=NewMagickWand(); | |
// Read input image file | |
if (status == MagickPass) { | |
//status = MagickReadImage(magick_wand,infile); | |
status = MagickReadImageBlob(magick_wand, contents, length); | |
} | |
// Rotate image clockwise 30 degrees with black background | |
if (status == MagickPass) { | |
PixelWand *background; | |
background=NewPixelWand(); | |
PixelSetColor(background,"#000000"); | |
status = MagickRotateImage(magick_wand,background,30); | |
DestroyPixelWand(background); | |
} | |
// Write output file | |
if (status == MagickPass) { | |
status = MagickWriteImage(magick_wand,outfile); | |
} | |
// Diagnose any error | |
if (status != MagickPass) { | |
char *description; | |
ExceptionType severity; | |
description=MagickGetException(magick_wand,&severity); | |
(void) fprintf(stderr,"%.1024s (severity %d)\n", description,severity); | |
} | |
// Release Wand handle | |
DestroyMagickWand(magick_wand); | |
// Destroy GraphicsMagick API | |
DestroyMagick(); | |
return (status == MagickPass ? 0 : 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment