Skip to content

Instantly share code, notes, and snippets.

@bellbind
Created July 1, 2009 14:28
Show Gist options
  • Save bellbind/138810 to your computer and use it in GitHub Desktop.
Save bellbind/138810 to your computer and use it in GitHub Desktop.
[C][gegl][tool] convert image to PNG thumbnail
/* make PNG thumbnail by gegl: http://gegl.org/
*
* build:
* gcc -Wall `pkg-config --cflags --libs gegl` geglthumbnail.c -o geglthumbnail
*
* usage:
* ./geglthumbnail image.xxx thumbnail.png
*
*/
#include <glib.h>
#include <glib/gprintf.h>
#include <gegl.h>
gint main(gint argc, gchar * argv[])
{
gchar * infile;
gchar * thumbfile;
gint thumbwidth = 200;
gint thumbheight = 150;
gegl_init(&argc, &argv);
if (argc < 3) return -1;
infile = argv[argc - 2];
thumbfile = argv[argc - 1];
{
GeglNode * gegl;
GeglNode * input;
GeglNode * output;
GeglNode * filter;
GeglRectangle bb;
// root node
gegl = gegl_node_new();
// operations specs see: http://gegl.org/operations.html
input = gegl_node_new_child(gegl,
"operation", "gegl:load",
"path", infile,
NULL);
bb = gegl_node_get_bounding_box(input);
//g_printf("%d %d\n", bb.height, bb.width);
output = gegl_node_new_child(gegl,
"operation", "gegl:png-save",
"path", thumbfile,
NULL);
// thumbnail filter
filter = gegl_node_new_child(gegl,
"operation", "gegl:scale",
"filter", "cubic",
"x", (thumbwidth - 2) / (gdouble) bb.width,
"y", (thumbheight - 2) / (gdouble) bb.height,
NULL);
// connect as: input -> filter -> output
gegl_node_link_many(input, filter, output, NULL);
// process image from input to output
gegl_node_process(output);
g_object_unref(gegl);
}
gegl_exit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment