added vips_image_write()

added a convenience function to write an image to a file
This commit is contained in:
John Cupitt 2011-05-24 12:53:29 +01:00
parent 2ba39ebc23
commit ef29872ce7
3 changed files with 27 additions and 6 deletions

View File

@ -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 );

View File

@ -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

View File

@ -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];