And why dont you give support to images with alpha channel, why? i thought img2pdf is full fledge library, please give support to this #103

Closed
opened 2021-06-01 19:01:08 +00:00 by rishabh3354 · 17 comments

Image contains transparency which cannot be retained in PDF.
img2pdf will not perform a lossy operation.
You can remove the alpha channel using imagemagick:
$ convert input.png -background white -alpha remove -alpha off output.png
Traceback (most recent call last):
File "/home/warlord/projects/JPG2PDF/src/jpg2pdf.py", line 511, in
window = MainWindow()
File "/home/warlord/projects/JPG2PDF/src/jpg2pdf.py", line 113, in init
f.write(img2pdf.convert(tt, colorspace=img2pdf.Colorspace.L))
File "/home/warlord/projects/jpg2pdf_env/lib/python3.6/site-packages/img2pdf.py", line 2102, in convert
) in read_images(rawdata, kwargs["colorspace"], kwargs["first_frame_only"]):
File "/home/warlord/projects/jpg2pdf_env/lib/python3.6/site-packages/img2pdf.py", line 1483, in read_images
imgdata, imgformat, default_dpi, colorspace, rawdata
File "/home/warlord/projects/jpg2pdf_env/lib/python3.6/site-packages/img2pdf.py", line 1189, in get_imgmetadata
raise AlphaChannelError("Refusing to work on images with alpha channel")
img2pdf.AlphaChannelError: Refusing to work on images with alpha channel

Image contains transparency which cannot be retained in PDF. img2pdf will not perform a lossy operation. You can remove the alpha channel using imagemagick: $ convert input.png -background white -alpha remove -alpha off output.png Traceback (most recent call last): File "/home/warlord/projects/JPG2PDF/src/jpg2pdf.py", line 511, in <module> window = MainWindow() File "/home/warlord/projects/JPG2PDF/src/jpg2pdf.py", line 113, in __init__ f.write(img2pdf.convert(tt, colorspace=img2pdf.Colorspace.L)) File "/home/warlord/projects/jpg2pdf_env/lib/python3.6/site-packages/img2pdf.py", line 2102, in convert ) in read_images(rawdata, kwargs["colorspace"], kwargs["first_frame_only"]): File "/home/warlord/projects/jpg2pdf_env/lib/python3.6/site-packages/img2pdf.py", line 1483, in read_images imgdata, imgformat, default_dpi, colorspace, rawdata File "/home/warlord/projects/jpg2pdf_env/lib/python3.6/site-packages/img2pdf.py", line 1189, in get_imgmetadata raise AlphaChannelError("Refusing to work on images with alpha channel") img2pdf.AlphaChannelError: Refusing to work on images with alpha channel
Author

Even i on on my ubuntu os, i took some screenshot images(officailycaptured by ubuntu ss), img2pdf is failed to convert it to pdf. says Refusing to work on images with alpha channel

Even i on on my ubuntu os, i took some screenshot images(officailycaptured by ubuntu ss), img2pdf is failed to convert it to pdf. says Refusing to work on images with alpha channel
Owner

Yes, and the error message you pasted explains why this is and what you can do about it. Where is the bug?

Yes, and the error message you pasted explains why this is and what you can do about it. Where is the bug?
Author

I was trying to make GUI application for jpg2pdf, but this library disappoint me, i will have to start from strach with PIL

I was trying to make GUI application for jpg2pdf, but this library disappoint me, i will have to start from strach with PIL
Author

Yes, and the error message you pasted explains why this is and what you can do about it. Where is the bug?

it should handle images with alpha channel all i am trying to say

> Yes, and the error message you pasted explains why this is and what you can do about it. Where is the bug? it should handle images with alpha channel all i am trying to say
Owner

img2pdf is for lossless conversion. If you do not require lossless conversion, then there are many existing libraries that do the job. You should use the right tool for the task at hand and if you want to be able to convert images and loose information, then either you manually remove the alpha channel (for example with Image.convert() from PIL) or img2pdf is the wrong library for you.

Also, please note, that img2pdf already has a rudimentary GUI. If you want to make a img2pdf GUI, you could consider improvin the existing GUI that is based on Tkinter to be platform independent.

img2pdf is for lossless conversion. If you do not require lossless conversion, then there are many existing libraries that do the job. You should use the right tool for the task at hand and if you want to be able to convert images and loose information, then either you manually remove the alpha channel (for example with `Image.convert()` from PIL) or img2pdf is the wrong library for you. Also, please note, that img2pdf already has a rudimentary GUI. If you want to make a img2pdf GUI, you could consider improvin the existing GUI that is based on Tkinter to be platform independent.
Owner

Yes, and the error message you pasted explains why this is and what you can do about it. Where is the bug?

it should handle images with alpha channel all i am trying to say

The reason I wrote img2pdf is not because there was no software to do so before. There are plenty of tools that do this job. Have a look at the bottom of the README.md for a list. The one thing that img2pdf does different from all the other tools is, that it is always lossless. Removing the alpha channel is a lossy operation and that's why img2pdf refuses to operate on images with alpha channels. If you use img2pdf, then you are guaranteed to not loose any pixel color information. If you don't need that then either perform the lossy operation of removing the alpha channel yourself before handing the image to img2pdf or use one of the many different libraries or applications that exist and which will happily convert images to pdf at the cost of either loosing information or needlessly increasing the output pdf size.

> > Yes, and the error message you pasted explains why this is and what you can do about it. Where is the bug? > > it should handle images with alpha channel all i am trying to say The reason I wrote img2pdf is not because there was no software to do so before. There are plenty of tools that do this job. Have a look at the bottom of the `README.md` for a list. The one thing that img2pdf does different from all the other tools is, that it is *always* lossless. Removing the alpha channel is a lossy operation and that's why img2pdf refuses to operate on images with alpha channels. If you use img2pdf, then you are guaranteed to not loose any pixel color information. If you don't need that then either perform the lossy operation of removing the alpha channel yourself before handing the image to img2pdf or use one of the many different libraries or applications that exist and which will happily convert images to pdf at the cost of either loosing information or needlessly increasing the output pdf size.
Author

img2pdf is for lossless conversion. If you do not require lossless conversion, then there are many existing libraries that do the job. You should use the right tool for the task at hand and if you want to be able to convert images and loose information, then either you manually remove the alpha channel (for example with Image.convert() from PIL) or img2pdf is the wrong library for you.

Also, please note, that img2pdf already has a rudimentary GUI. If you want to make a img2pdf GUI, you could consider improvin the existing GUI that is based on Tkinter to be platform independent.

i have seen that GUI, it is radiculus, Tkinter is good for learning purpose (very limited ), i use Pyqt5 (full fledge lib for gui), you should consider it

> img2pdf is for lossless conversion. If you do not require lossless conversion, then there are many existing libraries that do the job. You should use the right tool for the task at hand and if you want to be able to convert images and loose information, then either you manually remove the alpha channel (for example with `Image.convert()` from PIL) or img2pdf is the wrong library for you. > > Also, please note, that img2pdf already has a rudimentary GUI. If you want to make a img2pdf GUI, you could consider improvin the existing GUI that is based on Tkinter to be platform independent. i have seen that GUI, it is radiculus, Tkinter is good for learning purpose (very limited ), i use Pyqt5 (full fledge lib for gui), you should consider it
Owner

Cool! looking forward to your code! 😀

Cool! looking forward to your code! 😀
Author

Cool! looking forward to your code! 😀

where are you from btw ?

> Cool! looking forward to your code! 😀 where are you from btw ?
Owner

I live in Germany. Why do you ask? :)

I live in Germany. Why do you ask? :)
Author

okay, germany is good country, my application mostyly downloaded in germany and USa

okay, germany is good country, my application mostyly downloaded in germany and USa
Author

I live in Germany. Why do you ask? :)

i make apps for linux (snap package)

> I live in Germany. Why do you ask? :) i make apps for linux (snap package)
Author

I live in Germany. Why do you ask? :)

i make apps for linux (snap package)

some apps i published https://snapcraft.io/search?q=rishabh

> > I live in Germany. Why do you ask? :) > > i make apps for linux (snap package) some apps i published https://snapcraft.io/search?q=rishabh

FWIW, if rishabh3354 uses PyQt5 in his/her snaps then this looks like a license violation:

Details for JPG2PDF Pro - Images To PDF Converter

License Proprietary
Last updated 23 June 2021

source: https://snapcraft.io/jpg2pdf

Versus:

Meta License: GPL v3
Author: Riverbank Computing Limited

(source: https://pypi.org/project/PyQt5/ )

Also, the developer homepage link is currently broken:

https://warlordsoftwares.in/ -> 502 Bad Gateway nginx/1.10.3 (Ubuntu)
FWIW, if rishabh3354 uses PyQt5 in his/her snaps then this looks like a license violation: > Details for JPG2PDF Pro - Images To PDF Converter > > License Proprietary > Last updated 23 June 2021 ``` source: https://snapcraft.io/jpg2pdf ``` Versus: > Meta License: GPL v3 > Author: Riverbank Computing Limited (source: https://pypi.org/project/PyQt5/ ) Also, the developer homepage link is currently broken: ``` https://warlordsoftwares.in/ -> 502 Bad Gateway nginx/1.10.3 (Ubuntu) ```
Author

Hello gms,

first of all, Jpg2pdf is not a commercial application. its a open source app, and it uses PySide(quite similiar binding) not pyqt and it is available under the LGPL (like Qt itself), and thus can be used by proprietary programs provided that you carefully read and abide by the terms of the LGPL.

And about the https://warlordsoftwares.in , it was under maintainence, i had to migrate my django version. Now working like a charm.

And jpg2pdf is very useful application developed by me. More than 5000+ users are currently using it across various linux distribution.

Thanks!

Hello gms, first of all, Jpg2pdf is not a commercial application. its a open source app, and it uses PySide(quite similiar binding) not pyqt and it is available under the LGPL (like Qt itself), and thus can be used by proprietary programs provided that you carefully read and abide by the terms of the LGPL. And about the https://warlordsoftwares.in , it was under maintainence, i had to migrate my django version. Now working like a charm. And jpg2pdf is very useful application developed by me. More than 5000+ users are currently using it across various linux distribution. Thanks!
Contributor

first of all, Jpg2pdf is not a commercial application. its a open source app

Why is it marked as Proprietary on snapcraft then and sold on your website ("Purchase license: $1.99/only")? If you call it open source, why is the code not publicly available on some development platform such as GitHub or GitLab?
Furthermore, if your software is really written with PySide, why then claim in the description of your website that you are using PyQt? This all sounds very dubious to me.

> first of all, Jpg2pdf is not a commercial application. its a open source app Why is it marked as `Proprietary` on snapcraft then and sold on your website (`"Purchase license: $1.99/only"`)? If you call it open source, why is the code not publicly available on some development platform such as GitHub or GitLab? Furthermore, if your software is really written with PySide, why then claim in the description of your website that you are using PyQt? This all sounds very dubious to me.
Contributor

Concerning alpha channels:
It is simple. If you do not need to preserve the alpha channel, just remove it with PIL, and forward the output byte stream to img2pdf. I can provide some code if necessary.
Otherwise, it will be a bit more difficult. I recommend to check out an example shared by Jay Berkenbilt.
Moreover, img2pdf might support alpha channels in the future, at least for some types of images (#106)

Concerning alpha channels: It is simple. If you do not need to preserve the alpha channel, just remove it with PIL, and forward the output byte stream to img2pdf. I can provide some code if necessary. Otherwise, it will be a bit more difficult. I recommend to check out [an example shared by Jay Berkenbilt](https://github.com/qpdf/qpdf/issues/207#issuecomment-830702745). Moreover, img2pdf might support alpha channels in the future, at least for some types of images (https://gitlab.mister-muffin.de/josch/img2pdf/pulls/106)
Sign in to join this conversation.
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: josch/img2pdf#103
No description provided.