mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
New withMetadata([boolean]) to keep metadata in the generated images.
This commit is contained in:
19
src/sharp.cc
19
src/sharp.cc
@@ -33,6 +33,7 @@ struct resize_baton {
|
||||
int compressionLevel;
|
||||
int angle;
|
||||
std::string err;
|
||||
bool withMetadata;
|
||||
|
||||
resize_baton():
|
||||
buffer_in_len(0),
|
||||
@@ -42,7 +43,8 @@ struct resize_baton {
|
||||
max(false),
|
||||
sharpen(false),
|
||||
progressive(false),
|
||||
without_enlargement(false) {}
|
||||
without_enlargement(false),
|
||||
withMetadata(false) {}
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
@@ -585,37 +587,37 @@ class ResizeWorker : public NanAsyncWorker {
|
||||
VipsImage *output = cached;
|
||||
if (baton->output == "__jpeg" || (baton->output == "__input" && inputImageType == JPEG)) {
|
||||
// Write JPEG to buffer
|
||||
if (vips_jpegsave_buffer(output, &baton->buffer_out, &baton->buffer_out_len, "strip", TRUE, "Q", baton->quality, "optimize_coding", TRUE, "interlace", baton->progressive, NULL)) {
|
||||
if (vips_jpegsave_buffer(output, &baton->buffer_out, &baton->buffer_out_len, "strip", !baton->withMetadata, "Q", baton->quality, "optimize_coding", TRUE, "interlace", baton->progressive, NULL)) {
|
||||
return resize_error(baton, output);
|
||||
}
|
||||
} else if (baton->output == "__png" || (baton->output == "__input" && inputImageType == PNG)) {
|
||||
// Write PNG to buffer
|
||||
if (vips_pngsave_buffer(output, &baton->buffer_out, &baton->buffer_out_len, "strip", TRUE, "compression", baton->compressionLevel, "interlace", baton->progressive, NULL)) {
|
||||
if (vips_pngsave_buffer(output, &baton->buffer_out, &baton->buffer_out_len, "strip", !baton->withMetadata, "compression", baton->compressionLevel, "interlace", baton->progressive, NULL)) {
|
||||
return resize_error(baton, output);
|
||||
}
|
||||
} else if (baton->output == "__webp" || (baton->output == "__input" && inputImageType == WEBP)) {
|
||||
// Write WEBP to buffer
|
||||
if (vips_webpsave_buffer(output, &baton->buffer_out, &baton->buffer_out_len, "strip", TRUE, "Q", baton->quality, NULL)) {
|
||||
if (vips_webpsave_buffer(output, &baton->buffer_out, &baton->buffer_out_len, "strip", !baton->withMetadata, "Q", baton->quality, NULL)) {
|
||||
return resize_error(baton, output);
|
||||
}
|
||||
} else if (is_jpeg(baton->output)) {
|
||||
// Write JPEG to file
|
||||
if (vips_jpegsave(output, baton->output.c_str(), "strip", TRUE, "Q", baton->quality, "optimize_coding", TRUE, "interlace", baton->progressive, NULL)) {
|
||||
if (vips_jpegsave(output, baton->output.c_str(), "strip", !baton->withMetadata, "Q", baton->quality, "optimize_coding", TRUE, "interlace", baton->progressive, NULL)) {
|
||||
return resize_error(baton, output);
|
||||
}
|
||||
} else if (is_png(baton->output)) {
|
||||
// Write PNG to file
|
||||
if (vips_pngsave(output, baton->output.c_str(), "strip", TRUE, "compression", baton->compressionLevel, "interlace", baton->progressive, NULL)) {
|
||||
if (vips_pngsave(output, baton->output.c_str(), "strip", !baton->withMetadata, "compression", baton->compressionLevel, "interlace", baton->progressive, NULL)) {
|
||||
return resize_error(baton, output);
|
||||
}
|
||||
} else if (is_webp(baton->output)) {
|
||||
// Write WEBP to file
|
||||
if (vips_webpsave(output, baton->output.c_str(), "strip", TRUE, "Q", baton->quality, NULL)) {
|
||||
if (vips_webpsave(output, baton->output.c_str(), "strip", !baton->withMetadata, "Q", baton->quality, NULL)) {
|
||||
return resize_error(baton, output);
|
||||
}
|
||||
} else if (is_tiff(baton->output)) {
|
||||
// Write TIFF to file
|
||||
if (vips_tiffsave(output, baton->output.c_str(), "strip", TRUE, "compression", VIPS_FOREIGN_TIFF_COMPRESSION_JPEG, "Q", baton->quality, NULL)) {
|
||||
if (vips_tiffsave(output, baton->output.c_str(), "strip", !baton->withMetadata, "compression", VIPS_FOREIGN_TIFF_COMPRESSION_JPEG, "Q", baton->quality, NULL)) {
|
||||
return resize_error(baton, output);
|
||||
}
|
||||
} else {
|
||||
@@ -706,6 +708,7 @@ NAN_METHOD(resize) {
|
||||
baton->quality = options->Get(NanNew<String>("quality"))->Int32Value();
|
||||
baton->compressionLevel = options->Get(NanNew<String>("compressionLevel"))->Int32Value();
|
||||
baton->angle = options->Get(NanNew<String>("angle"))->Int32Value();
|
||||
baton->withMetadata = options->Get(NanNew<String>("withMetadata"))->BooleanValue();
|
||||
// Output filename or __format for Buffer
|
||||
baton->output = *String::Utf8Value(options->Get(NanNew<String>("output"))->ToString());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user