From ef29872ce75c3ff8a6177e40cb668f724debfeba Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 24 May 2011 12:53:29 +0100 Subject: [PATCH] added vips_image_write() added a convenience function to write an image to a file --- libvips/include/vips/image.h | 1 + libvips/iofuncs/image.c | 25 +++++++++++++++++++++++++ libvips/iofuncs/object.c | 7 +------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/libvips/include/vips/image.h b/libvips/include/vips/image.h index 420b1324..e696719f 100644 --- a/libvips/include/vips/image.h +++ b/libvips/include/vips/image.h @@ -363,6 +363,7 @@ VipsImage *vips_image_new_from_file_raw( const char *filename, VipsImage *vips_image_new_from_memory( void *buffer, int xsize, int ysize, int bands, VipsBandFormat bandfmt ); VipsImage *vips_image_new_disc_temp( const char *format ); +int vips_image_write( VipsImage *image, const char *filename ); gboolean vips_image_isMSBfirst( VipsImage *image ); gboolean vips_image_isfile( VipsImage *image ); diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index d27028f6..0b5be189 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -1736,6 +1736,31 @@ vips_image_new_disc_temp( const char *format ) return( image ); } +/** + * vips_image_write: + * @image: image to write + * @filename: write to this file + * + * A convenience function to write a #VipsImage to a file. + * + * Returns: 0 on success, or -1 on error. + */ +int +vips_image_write( VipsImage *image, const char *filename ) +{ + VipsImage *out; + + if( !(out = vips_image_new_from_file( filename, "w" )) ) + return( -1 ); + if( im_copy( image, out ) ) { + g_object_unref( out ); + return( -1 ); + } + g_object_unref( out ); + + return( 0 ); +} + /** * vips_image_isMSBfirst: * @image: image to test diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 28cca6c9..a1a6177e 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -1164,18 +1164,13 @@ vips_object_get_argument_to_string( VipsObject *object, if( G_IS_PARAM_SPEC_OBJECT( pspec ) && G_PARAM_SPEC_VALUE_TYPE( pspec ) == VIPS_TYPE_IMAGE ) { VipsImage *value; - VipsImage *image; - if( !(image = vips_image_new_from_file( arg, "w" )) ) - return( -1 ); g_object_get( object, name, &value, NULL ); - if( im_copy( value, image ) ) { + if( vips_image_write( value, arg ) ) { g_object_unref( value ); - g_object_unref( image ); return( -1 ); } g_object_unref( value ); - g_object_unref( image ); } else { char str[1000];