diff options
author | pajoye <none@none> | 2007-12-12 15:56:03 +0000 |
---|---|---|
committer | pajoye <none@none> | 2007-12-12 15:56:03 +0000 |
commit | f67452e1f82f1c2496e0859d638172bee74b43a0 (patch) | |
tree | b36302bc3d5b2a8a0af52e67970e1efb68dd5157 /examples | |
parent | 5583a4194a348870371f22cb9eb85d3eebfd372f (diff) | |
download | libgd-f67452e1f82f1c2496e0859d638172bee74b43a0.tar.gz |
- #136 add crop image support
- gdImageCrop, gdImageAutoCrop and gdImageThresholdCrop
- add gdRect struct to define a rectangle area at position (x,y) with
a given width and height
Diffstat (limited to 'examples')
-rw-r--r-- | examples/CMakeLists.txt | 6 | ||||
-rw-r--r-- | examples/crop.c | 88 | ||||
-rw-r--r-- | examples/test_crop_threshold.png | bin | 0 -> 7919 bytes |
3 files changed, 91 insertions, 3 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 842a6c4..26e2de4 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,14 +1,14 @@ -message("inc: ${GD_INCLUDE_DIR}") include_directories (BEFORE ${GD_SOURCE_DIR}/src "${CMAKE_BINARY_DIR}") SET(TESTS_FILES - tiffread + tiffread + tgaread + crop ) FOREACH(test_name ${TESTS_FILES}) add_executable(${test_name} "${test_name}.c") target_link_libraries (${test_name} ${GD_LIB}) - ADD_TEST(${test_name} ${EXECUTABLE_OUTPUT_PATH}/${test_name}) ENDFOREACH(test_name) diff --git a/examples/crop.c b/examples/crop.c new file mode 100644 index 0000000..f4e8a99 --- /dev/null +++ b/examples/crop.c @@ -0,0 +1,88 @@ +/* $Id$ */ +/* + * You can fetch a set of samples TIFF images here: + * ftp://ftp.remotesensing.org/pub/libtiff/ + * (pics-x.y.z.tar.gz) + */ + +#include "gd.h" +#include <stdio.h> +#include <stdlib.h> + +void save_png(gdImagePtr im, const char *filename) +{ + FILE *fp; + fp = fopen(filename, "wb"); + if (!fp) { + fprintf(stderr, "Can't save png image %s\n", filename); + return; + } + gdImagePng(im, fp); + fclose(fp); +} + +gdImagePtr read_png(const char *filename) +{ + FILE * fp; + gdImagePtr im; + + fp = fopen(filename, "rb"); + if (!fp) { + fprintf(stderr, "Can't read png image %s\n", filename); + return NULL; + } + im = gdImageCreateFromPng(fp); + fclose(fp); + return im; +} + +int main() +{ + gdImagePtr im, im2; + FILE *fp; + char path[2048]; + char dst[2048]; + + im = gdImageCreateTrueColor(400, 400); + + if (!im) { + fprintf(stderr, "Can't create 400x400 TC image\n", path); + return 1; + } + + gdImageFilledRectangle(im, 19, 29, 390, 390, 0xFFFFFF); + gdImageRectangle(im, 19, 29, 390, 390, 0xFF0000); + save_png(im, "a1.png"); + + im2 = gdImageAutoCrop(im, GD_CROP_SIDES); + if (im2) { + save_png(im2, "a2.png"); + gdImageDestroy(im2); + } + gdImageDestroy(im); + + im = read_png("test_crop_threshold.png"); + if (!im) { + return 1; + } + + im2 = gdImageThresholdCrop(im, 0xFFFFFF, 120); + if (im2) { + save_png(im2, "a3.png"); + gdImageDestroy(im2); + } + gdImageDestroy(im); + + im = read_png("test_crop_threshold.png"); + if (!im) { + return 1; + } + + im2 = gdImageThresholdCrop(im, 0xFFFFFF, 70); + if (im2) { + save_png(im2, "a4.png"); + gdImageDestroy(im2); + } + + gdImageDestroy(im); +} diff --git a/examples/test_crop_threshold.png b/examples/test_crop_threshold.png Binary files differnew file mode 100644 index 0000000..4a9dff1 --- /dev/null +++ b/examples/test_crop_threshold.png |