Skip to content

Instantly share code, notes, and snippets.

@joseph-montanez
Created July 14, 2011 15:47
Show Gist options
  • Save joseph-montanez/1082706 to your computer and use it in GitHub Desktop.
Save joseph-montanez/1082706 to your computer and use it in GitHub Desktop.
GD versus ImageMagic Resizing an Image
#include "gd.h"
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <sys/fcntl.h>
#include <time.h>
#include <ctype.h>
int main () {
char *fname = "/home/joseph/Pictures/1291237588319.jpg";
FILE *infile = fopen(fname, "rb");
gdImagePtr src_im = gdImageCreateFromJpeg(infile);
if (src_im != NULL) {
gdImagePtr dest_im = gdImageCreateTrueColor(
src_im->sx / 2, src_im->sy / 2
);
gdImageCopyResized(
dest_im, src_im, 0, 0, 0, 0,
src_im->sx / 2, src_im->sy / 2,
src_im->sx, src_im->sy
);
FILE *jpegout = fopen("foobar.jpg","wb+");
gdImageJpeg(dest_im, jpegout, -1);
fflush(jpegout);
puts("We good :)");
printf("%dx%d\n", src_im->sx, src_im->sy);
}
return 0;
}
#include <wand/MagickWand.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <sys/fcntl.h>
#include <time.h>
#include <ctype.h>
int main () {
char *fname = "/home/joseph/Pictures/1291237588319.jpg";
MagickWandGenesis();
MagickWand *magick_wand=NewMagickWand();
MagickBooleanType status=MagickReadImage(magick_wand, fname);
if (status != MagickFalse) {
MagickResetIterator(magick_wand);
while (MagickNextImage(magick_wand) != MagickFalse) {
MagickSampleImage(magick_wand,1650,1056);
}
status=MagickWriteImages(magick_wand,"foobar2.jpg",MagickTrue);
magick_wand=DestroyMagickWand(magick_wand);
MagickWandTerminus();
}
return 0;
}
all:
gcc gd-bench.c -lgd -o gd-bench
gcc `MagickWand-config --cflags --cppflags` magick-bench.c -o magick-bench `MagickWand-config --ldflags --libs`
time ./gd-bench
time ./magick-bench
#GD is faster 29% faster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment