Skip to content

Instantly share code, notes, and snippets.

@jcupitt
Created March 2, 2020 11:40
Show Gist options
  • Save jcupitt/c59271564f3cf93de4d535b066d1897d to your computer and use it in GitHub Desktop.
Save jcupitt/c59271564f3cf93de4d535b066d1897d to your computer and use it in GitHub Desktop.
watermark a fax image with libvips
/* watermark a fax image with vips8 C
*
* compile with
gcc -g -Wall watermark_fax.c `pkg-config vips --cflags --libs`
*/
#include <vips/vips.h>
int
main( int argc, char **argv )
{
VipsImage *base;
VipsImage **t;
VipsImage *in;
VipsImage *overlay;
if( VIPS_INIT( argv[0] ) )
vips_error_exit( NULL );
if( argc != 4 )
vips_error_exit( "usage: %s in-file out-file \"message\"",
argv[0] );
base = vips_image_new();
t = (VipsImage **) vips_object_local_array( VIPS_OBJECT( base ), 12 );
if( !(t[0] = vips_image_new_from_file( argv[1],
"access", VIPS_ACCESS_SEQUENTIAL,
NULL )) ) {
g_object_unref( base );
vips_error_exit( NULL );
}
in = t[0];
if( vips_text( &t[1], argv[3],
"width", 500,
"dpi", 300,
NULL ) ||
vips_embed( t[1], &t[7], 100, 100,
t[1]->Xsize + 200, t[1]->Ysize + 200, NULL ) ||
vips_replicate( t[7], &t[8],
1 + in->Xsize / t[7]->Xsize,
1 + in->Ysize / t[7]->Ysize, NULL ) ||
vips_crop( t[8], &t[9], 0, 0,
in->Xsize, in->Ysize, NULL ) ) {
g_object_unref( base );
vips_error_exit( NULL );
}
overlay = t[9];
/* EOR the image and overlay and write to output.
*/
if( vips_eorimage( in, overlay, &t[10], NULL ) ||
vips_image_write_to_file( t[10], argv[2], NULL ) ) {
g_object_unref( base );
vips_error_exit( NULL );
}
g_object_unref( base );
return( 0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment