Created
December 2, 2012 14:19
-
-
Save mrosset/4188939 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "thumb.h" | |
gdImagePtr loadImage(char *path) { | |
FILE *fp; | |
gdImagePtr im; | |
fp = fopen(path, "rb"); | |
if (!fp) { | |
assert_perror(errno); | |
} | |
im = gdImageCreateFromJpeg(fp); | |
fclose(fp); | |
return im; | |
} | |
void savePngImage(gdImagePtr im, char *path) { | |
FILE *fp; | |
fp = fopen(path, "wb"); | |
if (!fp) { | |
assert_perror(errno); | |
} | |
gdImagePng(im, fp); | |
fclose(fp); | |
gdFree(im); | |
} | |
void thumbnail(char *path, char *tpath) { | |
gdImagePtr src = loadImage(path); | |
int w, h, tw = 100, th = 100; | |
w = gdImageSX(src); | |
h = gdImageSY(src); | |
if ( w > h ) { | |
th = 100 * h / w; | |
fflush(stdout); | |
} | |
else { | |
tw = 100 * w / h; | |
} | |
gdImagePtr dst = gdImageCreateTrueColor(tw, th); | |
gdImageCopyResampled(dst, src, 0, 0, 0, 0, tw, th, w, h); | |
savePngImage(dst, tpath); | |
gdFree(src); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment