-
-
Notifications
You must be signed in to change notification settings - Fork 699
Add an option for strip metadata but without removing icc profile? #1026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you explain the use case? If you want to make very small thumbnail files, I would transform to sRGB and not attach a profile. If you want to remove most metadata but leave the profile, I would just remove individual tags. For example:
etc. |
thx @jcupitt In my case I want to make small thumbnails, but being used to display on iPhone, I want to keep the original DCI-P3 icc profile rather than transforming to sRGB for better screen performance. Removing other metadata and keeping icc should be able to handle it, I will do that at this moment. The option I want maybe is not necessary. |
Ah, OK, that makes sense. You can remove all fields like this:
And then reattach a profile. |
@jcupitt i met the same problem. but how to implement in c code ? |
The C API is documented here: https://libvips.github.io/libvips/API/current/libvips-header.html It's very close to Python. |
thank you in advance @jcupitt
|
There's been a change to metadata handling in libvips 8.9 -- you now need to Try:
|
I'll update that earlier answer, thanks for pointing this out. |
should be |
Don't use Plain In C, it's vips_copy(): https://libvips.github.io/libvips/API/current/libvips-conversion.html#vips-copy |
@jcupitt why won't c implementation remove fields? it works in python. could you please have a look at it, thanks very much
|
It is working I think. The jpeg writer always attaches some EXIF, since the spec requires it. I see:
|
Also, you need to free the result of It's really there for bindings. For C, I would use /* compile with:
*
* gcc -g -Wall remove-fields.c `pkg-config vips --cflags --libs`
*
*/
#include <stdio.h>
#include <vips/vips.h>
static void *
remove_fields( VipsImage *image, const char *name, GValue *value, void *a )
{
if ( strcmp(name, "icc-profile-data" ) != 0) {
printf("%s\n", name);
vips_image_remove(image, name);
}
return( NULL );
}
int
main( int argc, char **argv )
{
VipsImage *image;
VipsImage *x;
if( VIPS_INIT( argv[0] ) )
vips_error_exit( NULL );
if( argc != 3 )
vips_error_exit( "usage: %s infile outfile", argv[0] );
if( !(image = vips_image_new_from_file( argv[1], NULL )) )
vips_error_exit( NULL );
if( vips_copy( image, &x, NULL ) )
vips_error_exit( NULL );
g_object_unref( image );
image = x;
vips_image_map( image, remove_fields, NULL );
if( vips_image_write_to_file( image, argv[2], NULL ) )
vips_error_exit( NULL );
g_object_unref( image );
return( 0 );
} Now there's nothing to free, races are impossible and you don't need to write a loop. |
this may explain why there are some meta won't be deleted:
i will strip all metadata when saving images like this:
in which |
That EXIF block is only 186 bytes, and it is required by the JPEG specification. I would not remove it. |
@jcupitt Sorry to revive such an old topic, but I've found no way to do the same thing in PHP. As far as I can tell, |
Sorry, php-vips is missing Back when we designed php-vips-ext there was no good FFI package for php, so we had to do it in plain C. There does seem to be a reasonable FFI available now, so a better fix would be to get rid of php-vips-ext and just do everything in php-vips. It would make maintenance and installation much simpler. Like everything, it's a question of finding the time. If anyone would like to volunteer ... |
Thanks, I can see if I can add it to the extension (although I don't know if we personally can update^^). I can't promise anything as of now though. I'd avoid PHP FFI at least for now, it seems to be worse for performance since it needs to parse the definitions and load the symbols instead of having it compiled ahead of time with the extension. It would be a good idea in the long run though, building & installing the extension was a pain to set up for us (though mostly because of PHP Docker Images being stuck on an old version of Debian for so long). |
I agree, there would be a performance hit from using php-ffi, but I think only a small one. The improvement in portability, maintenance and ease of installation would be worth it (imo). There are some benchmarks here: https://github.com/libvips/libvips/wiki/Speed-and-memory-use ruby-vips has a fully interpreted FFI binding and runs the benchmark in 400ms, php-vips has a compiled binding and takes 350ms, so you might expect a FFI php-vips to be of the order of 10% slower. |
No description provided.
The text was updated successfully, but these errors were encountered: