Add default background metadata for PNG and GIF images

This commit is contained in:
Lovell Fuller
2021-07-19 14:55:22 +01:00
parent 719c2db8da
commit 3f08f6a359
6 changed files with 22 additions and 1 deletions

View File

@@ -90,6 +90,9 @@ class MetadataWorker : public Napi::AsyncWorker {
baton->subifds = image.get_int(VIPS_META_N_SUBIFDS);
}
baton->hasProfile = sharp::HasProfile(image);
if (image.get_typeof("background") == VIPS_TYPE_ARRAY_DOUBLE) {
baton->background = image.get_array_double("background");
}
// Derived attributes
baton->hasAlpha = sharp::HasAlpha(image);
baton->orientation = sharp::ExifOrientation(image);
@@ -209,6 +212,17 @@ class MetadataWorker : public Napi::AsyncWorker {
if (baton->subifds > 0) {
info.Set("subifds", baton->subifds);
}
if (!baton->background.empty()) {
if (baton->background.size() == 3) {
Napi::Object background = Napi::Object::New(env);
background.Set("r", baton->background[0]);
background.Set("g", baton->background[1]);
background.Set("b", baton->background[2]);
info.Set("background", background);
} else {
info.Set("background", baton->background[0]);
}
}
info.Set("hasProfile", baton->hasProfile);
info.Set("hasAlpha", baton->hasAlpha);
if (baton->orientation > 0) {

View File

@@ -42,6 +42,7 @@ struct MetadataBaton {
std::string compression;
std::vector<std::pair<int, int>> levels;
int subifds;
std::vector<double> background;
bool hasProfile;
bool hasAlpha;
int orientation;