Allow Lossy PDF #54
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
By Avner on 2018-12-30T15:39:56.173Z
First thing, Thanks for making this lib!
My use case is pretty simple, I get various png/jpegs/pdf from multiple resources I can not control and need to display them on the web.
For an easy client side behavior, we have decided to convert all to PDFs.
I do however get every once in a while this error:
Which is pretty descriptive and straight forward, I wonder however if it will be possible to add a flag to img2pdf that will basically allow a "lossy operation", In my case, I'd rather show something, than nothing.
Is this at all possible? or is there some inherent limitation I am missing?
Thoughts?
By josch on 2018-12-30T22:00:59.698Z
What stops you from removing the alpha channel from your input before passing them to img2pdf?
Why should img2pdf do the task and not your own code instead?
By Avner on 2018-12-31T10:08:39.168Z
@josch
For me, that would mean installing imagemagick and as a result, unneeded complexity with server and local dev setup.
Since this is a specific protection in img2pdf, I was thinking that it would be harmful to simply add a "force" flag, or "--allow-lossy".
I'd really just rather have this all in one. Maybe I am missing something, but I don't see why img2pdf should have this premise of "lossless", as in other converter, I'd expect this to have a default (lossless) but allow an opt-in override.
By josch on 2018-12-31T16:34:19.346Z
No, you don't have to install imagemagick. You can do the same with PIL which you must already have installed because img2pdf requires PIL. So removing the alpha channel is only a single line of code away:
The whole point of img2pdf is lossless conversion. If you want lossy conversion, then there exist tons of other tools already that are doing this task for you just fine (see README.md). Every additional command line option makes a tool harder to use because there is more documentation to read (not only more options have to be documented but also text has to be added like "yes, it is lossless except in these and those conditions..."). Every additional command line option makes the code more fragile because more conditions have to be handled and more unit tests have to be written. In contrast to all these downsides, the only thing that you have to do is to add a single line of code. So given how it is basically free for you to do this conversion, the additional complexity a "--allow-lossy" option would mean to img2pdf is not justified.
img2pdf aims to do one thing and this one thing well. That one thing is lossless conversion of raster images into a PDF container. If you want something else, then either add a single line into your code (see above) or use a different tool.
By Avner on 2018-12-31T16:53:14.165Z
@josch
This is perfect, thanks for the time you took to reply.
I guess the instruction to go with imagemagick in the exception warning me.
But I can totally see how this is a good generic recommendation.
Again, thanks for the guidance and patience here.
By Avner on 2018-12-31T16:53:14.464Z
Status changed to closed