diff options
author | pajoye <none@none> | 2008-02-27 23:25:00 +0000 |
---|---|---|
committer | pajoye <none@none> | 2008-02-27 23:25:00 +0000 |
commit | 41d830e0c110e378fc4473948390674f4ea65305 (patch) | |
tree | a51caf0fb7302e2188da863a6e3dfa0178974c2d /examples | |
parent | c9972ade5697bfc4763f3afa7a50a5bd10a36e82 (diff) | |
download | libgd-41d830e0c110e378fc4473948390674f4ea65305.tar.gz |
- #129:
- revert horizontal/vertical, was too confusing, it acts now like any
application (ie. gimp/ps) instead of talking about h/v axis
- optimize both
- add simple example
Diffstat (limited to 'examples')
-rw-r--r-- | examples/CMakeLists.txt | 15 | ||||
-rw-r--r-- | examples/flip.c | 76 |
2 files changed, 88 insertions, 3 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 368046f..0388d4c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,10 +3,19 @@ include_directories (BEFORE ${GD_SOURCE_DIR}/src "${CMAKE_BINARY_DIR}") SET(TESTS_FILES - tgaread + tiffread + resize + copyrotated + ellipseaa + ellipse + arc + ellipsearc + flip crop - nnquant - gif + ellfullaa + tgaread + nnquant + gif ) if (WIN32) diff --git a/examples/flip.c b/examples/flip.c new file mode 100644 index 0000000..99f2188 --- /dev/null +++ b/examples/flip.c @@ -0,0 +1,76 @@ +/* $Id$ */ +#include "gd.h" +#include <stdio.h> +#include <stdlib.h> +gdImagePtr loadImage(const char *name) +{ + FILE *fp; + gdImagePtr im; + + fp = fopen(name, "rb"); + if (!fp) { + fprintf(stderr, "Can't open jpeg file\n"); + gdImageDestroy(im); + return NULL; + } + + im = gdImageCreateFromJpeg(fp); + fclose(fp); + return im; +} + +int savePngImage(gdImagePtr im, const char *name) +{ + FILE *fp; + fp = fopen(name, "wb"); + if (!fp) { + fprintf(stderr, "Can't save png image fromtiff.png\n"); + return 0; + } + gdImagePng(im, fp); + fclose(fp); + return 1; +} + +int main(int argc, char **arg) +{ + gdImagePtr im; + int returncode = 0; + + if (argc < 2) { + fprintf(stderr, "Usage: flip [filename.png]\n"); + return 1; + } + + im = loadImage(arg[1]); + if (!im) goto error; + gdImageFlipHorizontal(im); + if (!savePngImage(im, "flip_horizontal.png")) { + goto error; + } + gdImageDestroy(im); + + im = loadImage(arg[1]); + if (!im) goto error; + gdImageFlipVertical(im); + if (!savePngImage(im, "flip_vertical.png")) { + goto error; + } + gdImageDestroy(im); + + im = loadImage(arg[1]); + if (!im) goto error; + gdImageFlipBoth(im); + if (!savePngImage(im, "flip_both.png")) { + goto error; + } + gdImageDestroy(im); + + goto done; + +error: + returncode = 1; + +done: + return returncode; +} |