diff --git a/examples/meson.build b/examples/meson.build index f75ac3b4..793ac583 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -2,6 +2,7 @@ examples = [ 'annotate-animated', 'new-from-buffer', 'progress-cancel', + 'use-vips-func', ] foreach example : examples diff --git a/examples/use-vips-func.c b/examples/use-vips-func.c new file mode 100644 index 00000000..0b8dc084 --- /dev/null +++ b/examples/use-vips-func.c @@ -0,0 +1,43 @@ +/* Example showing how to call a couple of vips functions using an input + * image file and creating an output file + * also gathers some info on the input image + */ +#include +#include + +int +main( int argc, char **argv ) +{ + VipsImage *in; + double mean; + VipsImage *out; + + if( VIPS_INIT( argv[0] ) ) + vips_error_exit( NULL ); + + if( argc != 3 ) + vips_error_exit( "usage: %s infile outfile", argv[0] ); + + if( !(in = vips_image_new_from_file( argv[1], NULL )) ) + vips_error_exit( NULL ); + + printf( "image width = %d\n", vips_image_get_width( in ) ); + + if( vips_avg( in, &mean, NULL ) ) + vips_error_exit( NULL ); + + printf( "mean pixel value = %g\n", mean ); + + /* generate photo nexative - replace with other vips_ funcs */ + if( vips_invert( in, &out, NULL ) ) + vips_error_exit( NULL ); + + g_object_unref( in ); + + if( vips_image_write_to_file( out, argv[2], NULL ) ) + vips_error_exit( NULL ); + + g_object_unref( out ); + + return( 0 ); +}