diff --git a/ChangeLog b/ChangeLog index 5c31aadc..8df93af0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,7 @@ - vips_gamma() works for any format - add --linear mode to vipsthumbnail - support XYZ as a PCS for vips_icc_import() and vips_icc_export() +- add --strip option to jpegsave 18/10/13 started 7.36.3 - fix compiler warnings in ubuntu 13.10 diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index c444bbe1..384a4e7f 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -1994,6 +1994,7 @@ vips_jpegload( const char *filename, VipsImage **out, ... ) * @profile: attach this ICC profile * @optimize_coding: compute optimal Huffman coding tables * @interlace: write an interlaced (progressive) jpeg + * @strip: remove all metadata from image * * Write a VIPS image to a file as JPEG. * @@ -2025,6 +2026,9 @@ vips_jpegload( const char *filename, VipsImage **out, ... ) * in jpg parlance). These files may be better for display over a slow network * conection, but need much more memory to encode and decode. * + * If @strip is set, no EXIF data, IPCT data, ICC profile or XMP metadata is + * written into the output file. + * * See also: vips_jpegsave_buffer(), vips_image_write_file(). * * Returns: 0 on success, -1 on error. @@ -2055,6 +2059,7 @@ vips_jpegsave( VipsImage *in, const char *filename, ... ) * @profile: attach this ICC profile * @optimize_coding: compute optimal Huffman coding tables * @interlace: write an interlaced (progressive) jpeg + * @strip: remove all metadata from image * * As vips_jpegsave(), but save to a memory buffer. * @@ -2104,6 +2109,7 @@ vips_jpegsave_buffer( VipsImage *in, void **buf, size_t *len, ... ) * @Q: JPEG quality factor * @profile: attach this ICC profile * @optimize_coding: compute optimal Huffman coding tables + * @strip: remove all metadata from image * * As vips_jpegsave(), but save as a mime jpeg on stdout. * diff --git a/libvips/foreign/jpegsave.c b/libvips/foreign/jpegsave.c index ec21af6d..6e4e5a5b 100644 --- a/libvips/foreign/jpegsave.c +++ b/libvips/foreign/jpegsave.c @@ -87,6 +87,10 @@ typedef struct _VipsForeignSaveJpeg { */ gboolean interlace; + /* Remove all metadata from the image. + */ + gboolean strip; + } VipsForeignSaveJpeg; typedef VipsForeignSaveClass VipsForeignSaveJpegClass; @@ -146,6 +150,13 @@ vips_foreign_save_jpeg_class_init( VipsForeignSaveJpegClass *class ) VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsForeignSaveJpeg, interlace ), FALSE ); + + VIPS_ARG_BOOL( class, "strip", 14, + _( "Strip" ), + _( "Strip all metadata from image" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsForeignSaveJpeg, strip ), + FALSE ); } static void @@ -181,7 +192,7 @@ vips_foreign_save_jpeg_file_build( VipsObject *object ) if( vips__jpeg_write_file( save->ready, file->filename, jpeg->Q, jpeg->profile, jpeg->optimize_coding, - jpeg->interlace ) ) + jpeg->interlace, jpeg->strip ) ) return( -1 ); return( 0 ); @@ -247,7 +258,7 @@ vips_foreign_save_jpeg_buffer_build( VipsObject *object ) if( vips__jpeg_write_buffer( save->ready, &obuf, &olen, jpeg->Q, jpeg->profile, jpeg->optimize_coding, - jpeg->interlace ) ) + jpeg->interlace, jpeg->strip ) ) return( -1 ); area = vips_area_new_blob( (VipsCallbackFn) vips_free, obuf, olen ); @@ -309,7 +320,7 @@ vips_foreign_save_jpeg_mime_build( VipsObject *object ) if( vips__jpeg_write_buffer( save->ready, &obuf, &olen, jpeg->Q, jpeg->profile, jpeg->optimize_coding, - jpeg->interlace ) ) + jpeg->interlace, jpeg->strip ) ) return( -1 ); printf( "Content-length: %zd\r\n", olen ); diff --git a/libvips/foreign/vips2jpeg.c b/libvips/foreign/vips2jpeg.c index fc47385b..f208bf7e 100644 --- a/libvips/foreign/vips2jpeg.c +++ b/libvips/foreign/vips2jpeg.c @@ -58,6 +58,8 @@ * - attach IPCT data (app13), thanks Gary * 2/10/13 Lovell Fuller * - add optimize_coding parameter + * 12/11/13 + * - add "strip" option to remove all metadata */ /* @@ -841,7 +843,7 @@ write_jpeg_block( REGION *region, Rect *area, void *a ) */ static int write_vips( Write *write, int qfac, const char *profile, - gboolean optimize_coding, gboolean progressive ) + gboolean optimize_coding, gboolean progressive, gboolean strip ) { VipsImage *in; J_COLOR_SPACE space; @@ -909,22 +911,26 @@ write_vips( Write *write, int qfac, const char *profile, /* Write any APP markers we need. */ - if( write_exif( write ) || - write_blob( write, VIPS_META_XMP_NAME, JPEG_APP0 + 1 ) || - write_blob( write, VIPS_META_IPCT_NAME, JPEG_APP0 + 13 ) ) - return( -1 ); + if( !strip ) { + if( write_exif( write ) || + write_blob( write, + VIPS_META_XMP_NAME, JPEG_APP0 + 1 ) || + write_blob( write, + VIPS_META_IPCT_NAME, JPEG_APP0 + 13 ) ) + return( -1 ); - /* A profile supplied as an argument overrides an embedded profile. - * "none" means don't attach a profile. - */ - if( profile && - strcmp( profile, "none" ) != 0 && - write_profile_file( write, profile ) ) - return( -1 ); - if( !profile && - vips_image_get_typeof( in, VIPS_META_ICC_NAME ) && - write_profile_meta( write ) ) - return( -1 ); + /* A profile supplied as an argument overrides an embedded + * profile. "none" means don't attach a profile. + */ + if( profile && + strcmp( profile, "none" ) != 0 && + write_profile_file( write, profile ) ) + return( -1 ); + if( !profile && + vips_image_get_typeof( in, VIPS_META_ICC_NAME ) && + write_profile_meta( write ) ) + return( -1 ); + } /* Write data. Note that the write function grabs the longjmp()! */ @@ -946,7 +952,7 @@ write_vips( Write *write, int qfac, const char *profile, int vips__jpeg_write_file( VipsImage *in, const char *filename, int Q, const char *profile, - gboolean optimize_coding, gboolean progressive ) + gboolean optimize_coding, gboolean progressive, gboolean strip ) { Write *write; @@ -976,7 +982,8 @@ vips__jpeg_write_file( VipsImage *in, /* Convert! */ - if( write_vips( write, Q, profile, optimize_coding, progressive ) ) { + if( write_vips( write, + Q, profile, optimize_coding, progressive, strip ) ) { write_destroy( write ); return( -1 ); } @@ -1223,7 +1230,8 @@ buf_dest( j_compress_ptr cinfo, void **obuf, size_t *olen ) int vips__jpeg_write_buffer( VipsImage *in, void **obuf, size_t *olen, int Q, const char *profile, - gboolean optimize_coding, gboolean progressive ) + gboolean optimize_coding, gboolean progressive, + gboolean strip ) { Write *write; @@ -1252,7 +1260,8 @@ vips__jpeg_write_buffer( VipsImage *in, /* Convert! */ - if( write_vips( write, Q, profile, optimize_coding, progressive ) ) { + if( write_vips( write, + Q, profile, optimize_coding, progressive, strip ) ) { write_destroy( write ); return( -1 ); diff --git a/libvips/foreign/vipsjpeg.h b/libvips/foreign/vipsjpeg.h index 246b51ad..ad328efe 100644 --- a/libvips/foreign/vipsjpeg.h +++ b/libvips/foreign/vipsjpeg.h @@ -39,10 +39,10 @@ extern const char *vips__jpeg_suffs[]; int vips__jpeg_write_file( VipsImage *in, const char *filename, int Q, const char *profile, - gboolean optimize_coding, gboolean progressive ); + gboolean optimize_coding, gboolean progressive, gboolean strip ); int vips__jpeg_write_buffer( VipsImage *in, void **obuf, size_t *olen, int Q, const char *profile, - gboolean optimize_coding, gboolean progressive ); + gboolean optimize_coding, gboolean progressive, gboolean strip ); int vips__isjpeg( const char *filename ); int vips__jpeg_read_file( const char *name, VipsImage *out,