Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* compile with
- *
- * gcc -g -Wall try269.c `pkg-config vips --cflags --libs`
- *
- */
- #include <stdio.h>
- #include <vips/vips.h>
- static int
- wof_generate_packshot(VipsImage **out, VipsImage *product) {
- VipsImage *base = vips_image_new();
- VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 12);
- int width = product->Xsize;
- int height = product->Ysize;
- if (
- // resize product image in t[0]
- vips_resize( product, &t[0], 0.9, NULL ) ||
- // find pixels over 250 and feather slightly ... JPG compression arifacts
- // will typically be around this range
- //
- // bandand() ANDs all the tests together, ie. we find pixels where r AND g
- // AND b are all >250
- vips_more_const1( t[0], &t[1], 250.0, NULL ) ||
- vips_bandand( t[1], &t[2], NULL ) ||
- vips_gaussblur( t[2], &t[3], 1,
- "precision", VIPS_PRECISION_INTEGER,
- NULL ) ||
- /* Make the new background, and blend with our product shot.
- */
- !(t[4] = vips_image_new_from_image1( t[0], 230 )) ||
- vips_ifthenelse( t[3], t[4], t[0], &t[5],
- "blend", TRUE,
- NULL ) ||
- /* Expand outwards with the new background colour.
- */
- vips_gravity( t[5], out, VIPS_COMPASS_DIRECTION_CENTRE, width, height,
- "extend", VIPS_EXTEND_COPY,
- NULL )
- ) {
- g_object_unref(base);
- return 1;
- }
- g_object_unref(base);
- return 0;
- }
- int
- main( int argc, char **argv )
- {
- int i;
- if( VIPS_INIT( argv[0] ) )
- vips_error_exit( NULL );
- for( i = 1; i < argc; i++ ) {
- VipsImage *in;
- VipsImage *x;
- printf( "loop %d ...\n", i );
- if( !(in = vips_image_new_from_file( argv[i],
- "access", VIPS_ACCESS_SEQUENTIAL,
- NULL )) )
- vips_error_exit( NULL );
- if( wof_generate_packshot( &x, in ) )
- vips_error_exit( NULL );
- if( vips_image_write_to_file( x, "x.jpg", NULL ) )
- vips_error_exit( NULL );
- g_object_unref( x );
- g_object_unref( in );
- }
- return( 0 );
- }
Add Comment
Please, Sign In to add comment