question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image opacity option not working

See original GitHub issue

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' });

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
chunyenHuangcommented, Mar 7, 2020
Screen Shot 2020-03-06 at 9 45 24 PM The new version should fix this issue for you.
1reaction
chunyenHuangcommented, Mar 7, 2020

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 .image twice with different opacity setups. It is a bug that the xObject is cached so the opacity is locked to the first image.

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);
    });
});

Read more comments on GitHub >

github_iconTop Results From Across the Web

Background Image opacity not working [HTML/CSS]
I am trying to set my background image to opaque keeping the content clearly visible. So far what I have tried do not...
Read more >
Solved: Transparency not Working on Image
Hi,. I uploaded an image to my app and I wanted to make it the background and make it a little more transparent...
Read more >
How to change background-image opacity in CSS without ...
Quick solution to how you can change background-image opacity using CSS without affecting the text content or child HTML elements.
Read more >
Elementor image transparency issues - WordPress.org
The setting for image opacity isn't in your theme settings though. If you open a page in Elementor and then click on the...
Read more >
Opacity Slider on a layer not working
The opacity slider cannot be moved on a background layer. So in that case just click the lock symbol to turn it into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found