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 Support? #28

Open
MOuli90 opened this issue Aug 5, 2014 · 6 comments
Open

PNG Support? #28

MOuli90 opened this issue Aug 5, 2014 · 6 comments

Comments

@MOuli90
Copy link

MOuli90 commented Aug 5, 2014

Why does HummusJS (PDF-Writer) not support images in the png format?

Is it possiable to copy the code of the ZF1 into this Project?

https://raw.githubusercontent.com/zendframework/zf1/master/library/Zend/Pdf/Resource/Image/Png.php

@galkahana
Copy link
Owner

hi. I just didnt write support for it. tjats the only reason. what you could do is either port the code to the lib, or use as is and import the pdf result as an image to the pdf created by hummus.

@linus-amg
Copy link

where would be the starting point to make a pr for png support? that would be really great for autographs

@galkahana
Copy link
Owner

Before you go into that then by FAR the simplest solution is to find an existing module that creates PDFs from PNGs and embedding the PDF. Seriously, the alternative of building it yourself is significantly more time consuming and involved. imagemagick can probably help here.

If you do decide to do this internal to Hummus, Best would be to do this in the C++ code where you can surely access all the relevant hooks in hummus to create the objects you need. plus this way it's accessible to everyone. Still if you prefer to focus on javascript and missing some necessary hooks that are available on PDFWriter, let me know and we'll figure out how to open them up.

In any case, since hummusJS is mostly a wrapper around the C++ library, the best way to learn on how to add images types to hummus is to look into its implementation of AbstractContentContext::DrawImage and do the JS equivalent. follow the track of how jpg images are drawn because it's the simplest.

This will get you the details on how to add an image type in general.

You will need to know 2 more things:

  1. how to specifically encode png into pdf.
  2. how to support transparency in png.

To do 1, the best is to look for an existing implementation. someone that already converts png to pdf, and use the pdfwriter/hummusjs library to do the equivalent PDF stuff. Reading png will probably take libpng. if you cant find anything then it will take reading into libpng, figuring out how to get the color samples and creating the image object by yourself. yummy. in this case better read on how to create images objects (section 4.8) in the PDF specs
. Following the JPG image creation trail in hummus will show you a simple example on how to implement images objects in PDF.

In case while reading 1 you didn't stumble upon a solution on how to carry transparency information, and you want transparency (in my tiff solution i got lazy and didn't), then you'll have to learn how to:

  1. read transparency samples from PNG. libpng can help you with that. i guess.
  2. create an image mask in the PDF and use it every time you use the image you created earlier. read about them in section 4.8.5 of the PDF specs. This will be good for alpha values that are either 1 or 0. if you want to support interim values, to support something like RGBA (don't know what they have in PNG), you can use Soft-mask images which are like image marks but allow interim values. read about them in page 553.

If you manage to do this, you will have my deep admiration and thanks. it is defo possible, and i done such things myself. it's just that it's not super trivial and will take time. I would clear something like 2 weeks for this and hope to get lucky and finish sooner.

@linus-amg
Copy link

linus-amg commented Jul 26, 2016

wow that sounds super challenging, all i really need is to add an image with mayority alpha 1 pixels (no interims), like an autograph, without putting white background above the existing pdf, sounds easier to read the pdf at the position were the image will be inserted and snapshot a background of that area and use it as the background of the jpg autograph 🍭

thank you very much for your help and describing where to take the first steps, appreciate it lots

@galkahana
Copy link
Owner

Folks. if anyone's looking to solve this. what's commonly done is to turn the PNG into a PDF using something like PDFKit, and then you can import it to hummus like an image.

@galkahana galkahana reopened this Jul 29, 2017
@mLuby
Copy link

mLuby commented Jun 25, 2018

NM Simple image drawing from the wiki works for PNGs.

I noticed this section about PNG images, but trying it doesn't seem to work. Did it work in the past or perhaps it's just optimistic wikiing? 😄

Also this issue seems to suggest some support for PNGs…

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

4 participants