Skip to content
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

Png with transparency is added twice #902

Closed
wasa4587 opened this issue Jan 8, 2019 · 6 comments
Closed

Png with transparency is added twice #902

wasa4587 opened this issue Jan 8, 2019 · 6 comments

Comments

@wasa4587
Copy link

wasa4587 commented Jan 8, 2019

Bug Report

Description of the problem

When I try to insert a png with transparency into the document, the image is inserted twice.

this is the image:
https://drive.google.com/file/d/1Paci2YPG0PAvnvNgGlVazkn3cL8txICt/view?usp=sharing

this is the output pdf
https://drive.google.com/file/d/1O3sRSiHnLCpRkiflb7tjzWfxGh7xbvSf/view?usp=sharing

Code sample

const PDFDocument = require('pdfkit');
const fs = require('fs');

  const doc = new PDFDocument( {
    layout: 'portrait',
    size: 'letter',
    margin: 0,
  });

  doc.image('./google0.026317087946030382.png', 0 ,0 , { width: 150, height: 100});

  const pdfFile = `./output.pdf`;
  doc.pipe(fs.createWriteStream(pdfFile));
  doc.end();  

Your environment

  • pdfkit version: ^0.8.3
  • Node version: v8.10.0
  • Operating System: ubuntu:16.04 and Windows 10
@sboudouk
Copy link

sboudouk commented Jan 9, 2019

Same issue here.

@swftvsn
Copy link

swftvsn commented Jan 9, 2019

we use https://github.com/lovell/sharp to preprocesses image on the fly to produce consistent results across wide variety of images. It handles multiple formats so we can accept images in many formats and produce predictable pdfs without worrying about users supplying webp or other formats.

@sboudouk
Copy link

sboudouk commented Jan 9, 2019

A quickfix found according to #339 , saving as PNG24 and not as sRGB (with photoshop, for example) makes the issue disappear.

@wasa4587
Copy link
Author

wasa4587 commented Jan 9, 2019

I just tested #891, it fixes my issue, nevertheless is not deployed in npm yet

@ggaabe
Copy link

ggaabe commented Jan 9, 2019

I used Imagemagick to produce consistent results by flattening the PNG and then converting it to jpg:

const spawn = require('child-process-promise').spawn;

const tempLocalFile = path.join(os.tmpdir(), filePath);
//load image into tempLocalFile location ^^
const tempLocalThumbFile = path.join(os.tmpdir(), thumbFilePath + ".jpg");

      return spawn('convert', [tempLocalFile, '-thumbnail', `${THUMB_MAX_WIDTH}x${THUMB_MAX_HEIGHT}>`, '-flatten', tempLocalThumbFile], {capture: ['stdout', 'stderr']});

@blikblum
Copy link
Member

Version 0.9 should fix thix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants