Add pdfBackground constructor property (#4207)

This commit is contained in:
Caleb Meredith
2024-09-06 07:31:43 -04:00
committed by GitHub
parent fc32e0bd3f
commit 7ee54810d4
8 changed files with 46 additions and 4 deletions

View File

@@ -109,6 +109,10 @@ namespace sharp {
if (HasAttr(input, "subifd")) {
descriptor->subifd = AttrAsInt32(input, "subifd");
}
// // PDF background color
if (HasAttr(input, "pdfBackground")) {
descriptor->pdfBackground = AttrAsVectorOfDouble(input, "pdfBackground");
}
// Create new image
if (HasAttr(input, "createChannels")) {
descriptor->createChannels = AttrAsUint32(input, "createChannels");
@@ -402,6 +406,9 @@ namespace sharp {
if (imageType == ImageType::TIFF) {
option->set("subifd", descriptor->subifd);
}
if (imageType == ImageType::PDF) {
option->set("background", descriptor->pdfBackground);
}
image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
image = SetDensity(image, descriptor->density);
@@ -506,6 +513,9 @@ namespace sharp {
if (imageType == ImageType::TIFF) {
option->set("subifd", descriptor->subifd);
}
if (imageType == ImageType::PDF) {
option->set("background", descriptor->pdfBackground);
}
image = VImage::new_from_file(descriptor->file.data(), option);
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
image = SetDensity(image, descriptor->density);

View File

@@ -74,6 +74,7 @@ namespace sharp {
int textSpacing;
VipsTextWrap textWrap;
int textAutofitDpi;
std::vector<double> pdfBackground;
InputDescriptor():
buffer(nullptr),
@@ -108,7 +109,8 @@ namespace sharp {
textRgba(false),
textSpacing(0),
textWrap(VIPS_TEXT_WRAP_WORD),
textAutofitDpi(0) {}
textAutofitDpi(0),
pdfBackground{ 255.0, 255.0, 255.0, 255.0 } {}
};
// Convenience methods to access the attributes of a Napi::Object