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

Feature optional JPEG alpha channel #553

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

hhelwich
Copy link

@hhelwich hhelwich commented Oct 6, 2016

I have a use case where big PDF files should be generated with many big JPEG files. The JPEG files must not be changed so that the Exif and other meta data stays intact. I found out that this is possible with PDFKit.

I have the additional requirement that the JPEG files can have an alpha channel. I found that PDFKit supports that for PNG files but not for JPEG files. I also found out that it's not difficult to add this feature to PDFKit. I added an extra option alpha which can be used to add a grayscale JPEG mask. When the parameter is not used the current behavior is retained. Example usage:

const doc = new PDFDocument();
doc.image('foo.jpg', 0, 15, { width: 300, alpha: 'foo_mask.jpg' });

I would be glad if you think this feature is of general interest and accept it. If you don't find this feature helpful feel free to decline the pull request. Nevertheless i would be glad to get some feedback. E.g. i increased the PDF version to 1.4 because transparency was not possible in PDF 1.3 but i am not sure if this is without side effects.

@devongovett
Copy link
Member

Interesting. Why is this specific to JPEG? Can we have a mask option for all image types?

@hhelwich
Copy link
Author

I did it specific for JPEGs because i only needed it there. But i think it's a good idea to have the mask for all image types.
PNGs can have alpha transparency included. What should we do if an additional alpha transparency mask is specified?

@hhelwich
Copy link
Author

I added the alpha option also for PNG images. If the alpha parameter is not used, the original behavior is retained. If the PNG image has an alpha channel and also the alpha option is used, the alpha channel given by the alpha option is used instead of the alpha channel included in the PNG image.

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

Successfully merging this pull request may close these issues.

3 participants