add --strip option to jpegsave

drops all metadata
This commit is contained in:
John Cupitt 2013-11-12 17:30:33 +00:00
parent 53e86e71f4
commit 847332a77e
5 changed files with 52 additions and 25 deletions

View File

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

View File

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

View File

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

View File

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

View File

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