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
Image opacity option not working #175
Comments
It seems to me the range for opacity is 0.0 - 1.0 |
It doesn't matter the number you use in the option:
It doesn't work, because the option is never used in the library, if you open the file /node_modules/hummus-recipe/lib/image.js you can se the option been declared, but is never used: `/**
exports._getImgOffset = function _getImgOffset(imgSrc = '', options = {}) {
};` |
@ytaborda17 Please don't be mad. It does not mean the I just run the following test and it seems to me the opacity works as expected. Please see the attached screen shot. const path = require('path');
const HummusRecipe = require('../lib');
describe('Modify', () => {
const taskATP = 'Add transparent png';
it(taskATP, (done) => {
const src = path.join(__dirname, 'materials/test.pdf');
const output = path.join(__dirname, `output/${taskATP}.pdf`);
const wikiPng = path.join(__dirname, 'materials/wiki.png');
const recipe = new HummusRecipe(src, output);
recipe
.editPage(1)
.image(wikiPng, 'center', 'center', {
width: 300,
height: 300,
align: 'center center',
opacity: 0.5,
})
.endPage()
.endPDF(done);
});
}); If you still can not make it work, please post your code so I can take a look for you. |
Ok, still not working, thanks any way, as you said, here is the code: async function newPdf(data) {
const order = Object.keys(data.cotizar.companias).sort();
// client files + folder
const fileName = data.quoteId + '.pdf';
const folderName = data.nid + data.nid_dv;
// pdf
const origPath = PDF_PATH + 'base.pdf';
const destPath = PDF_PATH + '/' + folderName + '/' + fileName;
// logos
const p = require('path')
let logos = {
path: p.join(__dirname, '../../shared/logos/'),
files: {
partner: data.user.partner.name
}
};
common.createFolder(PDF_PATH + '/', folderName);
return await new Promise((resolve, reject) => {
const pdfDoc = new HummusRecipe(origPath, destPath);
resolve(pdfDoc);
}).then((page1header) => { // page1header
page1header.editPage(1);
if (data.user.partner.logo.indexOf('http') !== -1) {
page1header.image(logos.path + logos.files.partner, 700, 32, {
width: 100,
height: 30,
keepAspectRatio: true,
align: 'center center'
});
// water mark
page1header.image(logos.path + logos.files.partner, 361, 326, { // center: 371, 306,
width: 600,
height: 450,
keepAspectRatio: true,
opacity: 0.3,
align: 'center center'
});
}
page1header.text(data.form.date, 119, 40, { color: '#000000', size: 7 })
.text('No: ' + data.quoteId, 665, 550, { color: '#000000', size: 7, bold: true })
.text(data.form.name.toUpperCase(), 145, 63, { color: '#000000', size: 7 })
.text(`${data.form.badge} ${data.form.cold}`, 370, 61, { color: '#000000', size: 7 })
.text(common.currency(data.form.value, 0), 626, 83, { color: '#000000', size: 9, align: 'center', bold: true })
return page1header;
}).then((page2) => { // pag 2
let x = 60;
let y = 170;
order.forEach(item => {
if (item) {
// ... print image and text an stuff
// ... everything ok here
}
});
page2.endPage().endPDF();
return page2;
}).then(() => { //Upload and save
return {
destPath: destPath,
awsPath: 'path/' + folderName + '/' + fileName,
quoteId: data.quoteId
};
}).catch(err => {
throw new ErrorHandler(500, '--> Code not working U suck!', err);
});
} So, what I'm I doing wrong? Beacuse, with or without an opacity option, the image is printed but in full color. I'm using Node 12.16.1, and before you say it, a downgrade is not a solution. |
Oh I see the where the issue is. page1header.image(logos.path + logos.files.partner, 700, 32, {
width: 100,
height: 30,
keepAspectRatio: true,
align: 'center center'
});
// water mark
page1header.image(logos.path + logos.files.partner, 361, 326, { // center: 371, 306,
width: 600,
height: 450,
keepAspectRatio: true,
opacity: 0.3,
align: 'center center'
}); You called I can reproduce this bug with the following codes const path = require('path');
const HummusRecipe = require('../lib');
describe('Modify', () => {
const taskATP = 'Add transparent png';
it(taskATP, (done) => {
const src = path.join(__dirname, 'materials/test.pdf');
const output = path.join(__dirname, `output/${taskATP}.pdf`);
const wikiPng = path.join(__dirname, 'materials/wiki.png');
const recipe = new HummusRecipe(src, output);
recipe
.editPage(1)
.image(wikiPng, 'center', 50, {
width: 300,
height: 300,
align: 'center center',
opacity: 0.8,
})
.image(wikiPng, 'center', 'center', {
width: 300,
height: 300,
align: 'center center',
opacity: 0.1,
})
.endPage()
.endPDF(done);
});
}); |
I tried to use the opacity option with an image and is not working, if you open the file image in node_modules, you can see option.opacity declared but never used, but the documentation says you can use that property, in resume: it's not working
pdf.image(path + fileName, 361, 326, { width: 600, height: 450, keepAspectRatio: true, opacity: 10, align: 'center center' });
The text was updated successfully, but these errors were encountered: