From 767bfc3b7f51a6a1a8e30b5d871f9bf6e2f44f8e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 13 Nov 2012 20:09:30 +0000 Subject: [PATCH] allow absolute file names in vipsthumbnail -o thanks fuho --- ChangeLog | 1 + tools/vipsthumbnail.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c07f4b6..7df724de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ - update for new glib threading API - remove no threads option, glib no longer support it - better --help output for vips driver prog +- vipsthumbnail -o allows absolute file names 2/10/12 started 7.30.4 - remove options from format string in .dzi (thanks Martin) diff --git a/tools/vipsthumbnail.c b/tools/vipsthumbnail.c index 17e0cc0b..a04d333c 100644 --- a/tools/vipsthumbnail.c +++ b/tools/vipsthumbnail.c @@ -31,6 +31,8 @@ * - remove "--nodelete" option, have a --delete option instead, off by * default * - much more gentle extra sharpening + * 13/11/12 + * - allow absolute paths in -o (thanks fuho) */ #ifdef HAVE_CONFIG_H @@ -306,25 +308,35 @@ thumbnail3( IMAGE *in, IMAGE *out ) static char * make_thumbnail_name( const char *filename ) { - char *dir; char *file; char *p; char buf[FILENAME_MAX]; char *result; - dir = g_path_get_dirname( filename ); file = g_path_get_basename( filename ); + /* Remove the suffix from the file portion. + */ if( (p = strrchr( file, '.' )) ) *p = '\0'; + /* output_format can be an absolute path, in which case we discard the + * path from the incoming file. + */ im_snprintf( buf, FILENAME_MAX, output_format, file ); - result = g_build_filename( dir, buf, NULL ); + if( g_path_is_absolute( output_format ) ) + result = g_strdup( buf ); + else { + char *dir; + + dir = g_path_get_dirname( filename ); + result = g_build_filename( dir, buf, NULL ); + g_free( dir ); + } if( verbose ) - printf( "thumbnailing %s as %s\n", filename, buf ); + printf( "thumbnailing %s as %s\n", filename, result ); - g_free( dir ); g_free( file ); return( result );