Issue with colorspace #16

Closed
opened 2021-04-25 19:57:36 +00:00 by josch · 0 comments
Owner

By josch on 2015-03-15T09:41:52.007Z

Created by: ekianjo

When I run img2pdf on a back of pictures downloaded from GoogleBooks, I get the issue "unsupported colorspace" for some of the PNGs inside the folder.

I changed the colorspace to 1 and it makes it work for text only pages but it fails on other pages... any idea how I could ensure it selects the right colorspace by itelf depending on the picture?

Imported comments:

By josch on 2013-10-20 18:05:33 UTC

Can you supply an example image?

By ekianjo on 2013-10-21 00:50:50 UTC

Sure. Will send it later tonight.

By ekianjo on 2013-10-21 14:07:49 UTC

Here it is
guy de maupassant - afloat page-005

By josch on 2013-10-21 14:25:32 UTC

First of all, this *.png image is actually a jpeg image.

Second of all, I dont have any problems with converting above image into pdf.

The colorspace is selected automatically by PIL. Can you tell me which colorspace it selects for you by running it with the --verbose option? It correctly identifies it as RGB here.

By TonyStark on 2014-10-22 14:05:45 UTC

I also get problem unsupported color space: P and unsupported color space: RGBA Error

By josch on 2014-11-02 07:30:59 UTC

@TonyStark please provide more info by giving an example image and the output with the --verbose option

By DarwinAwardWinner on 2014-11-06 07:59:30 UTC

By the way, you can easily generate a test file by converting a PNG to indexed colorspace in GIMP (Image -> Mode -> Indexed) and saving it.

By TonyStark on 2014-11-10 09:06:50 UTC

@josch --verbose give me below output

D: input dpi = 96 x 96
D: input colorspace = RGBA
D: width x height = 1597 x 2100
D: imgformat = PNG
E: unsupported color space: RGBA

By DarwinAwardWinner on 2014-11-10 09:11:21 UTC

Are you sure you're using a version of picopt from after #18 was merged?

By TonyStark on 2014-11-10 09:12:01 UTC

@DarwinAwardWinner
no, let me try with that version..

By TonyStark on 2014-11-10 09:18:28 UTC

@DarwinAwardWinner
Thanx....
I update img2pdf.py and now works
--verbose give me this output

D: Reading test.png
D: input dpi = 96 x 96
D: input colorspace = RGBA
D: width x height = 1597 x 2100
D: imgformat = PNG
D: Converting colorspace RGBA to RGB

By josch on 2014-11-10 09:18:32 UTC

I released 0.1.3 which includes the fixes by @DarwinAwardWinner and some fix of mine. I'm able to convert the test input of @TonyStark with that version. Give it a try!

By josch on 2014-11-10 09:19:01 UTC

It's also on pypi if that matters.

By TonyStark on 2014-11-10 09:21:04 UTC

@josch
Now Working with RGBA to RGB and P to RGB
No any error... 👍

By DarwinAwardWinner on 2014-11-10 09:21:19 UTC

I will say, though, having to convert indexed color to RGB is a little unfortunate, since it increases the file size a good bit. (Compare to imagemagick's "convert" utility converting png to pdf.) I wish I knew PIL well enough to write a special-case for indexed color inputs.

By TonyStark on 2014-11-10 09:24:21 UTC

@DarwinAwardWinner
well ghostscript is best to compress pdf instead using imagemagick to compress png...
test.png --> img2pdf --> out.pdf [1.2mb] ---> Ghostscript ---> out2.pdf [184kb]

By DarwinAwardWinner on 2014-11-10 09:27:47 UTC

Huh. I'll have to try that.

By josch on 2014-11-10 09:31:31 UTC

@DarwinAwardWinner imagemagick is able to convert indexed pngs to pdf at reduced size compared to img2pdf because it is lossy. The purpose of img2pdf is to not be lossy

@TonyStark your ghostscript step is lossy, so no need to use img2pdf

The limitation here is the image formats that PDF can read. The choices are JPEG, JP2 and Flate. The first two are lossy jpeg encodings (which img2pdf makes lossless if the input is a jpeg as well) and the last is just a zipped raw RGB, Grayscale or Black/White stream. To my knowledge, there is no option for palletted images there. So an image with indexed input image can only be converted to RGB to work with PDF.

By TonyStark on 2014-11-10 09:40:45 UTC

@josch
ya its lossy output of ghostscript, but its good to readable

By josch on 2014-11-10 14:43:59 UTC

@TonyStark but if you want lossless in the first place, then what use is img2pdf for you?

By TonyStark on 2014-11-10 16:29:33 UTC

@josch
im just giving example of size reducing..

By josch on 2014-11-10 18:03:44 UTC

This seems to be solved. Closing.

*By josch on 2015-03-15T09:41:52.007Z* *Created by: ekianjo* When I run img2pdf on a back of pictures downloaded from GoogleBooks, I get the issue "unsupported colorspace" for some of the PNGs inside the folder. I changed the colorspace to 1 and it makes it work for text only pages but it fails on other pages... any idea how I could ensure it selects the right colorspace by itelf depending on the picture? **Imported comments:** *By josch on 2013-10-20 18:05:33 UTC* Can you supply an example image? *By ekianjo on 2013-10-21 00:50:50 UTC* Sure. Will send it later tonight. *By ekianjo on 2013-10-21 14:07:49 UTC* Here it is ![guy de maupassant - afloat page-005](https://f.cloud.github.com/assets/2460824/1372915/27bb3ece-3a5a-11e3-998e-84063a848a58.png) *By josch on 2013-10-21 14:25:32 UTC* First of all, this *.png image is actually a jpeg image. Second of all, I dont have any problems with converting above image into pdf. The colorspace is selected automatically by PIL. Can you tell me which colorspace it selects for you by running it with the --verbose option? It correctly identifies it as RGB here. *By TonyStark on 2014-10-22 14:05:45 UTC* I also get problem ```unsupported color space: P``` and ```unsupported color space: RGBA``` Error *By josch on 2014-11-02 07:30:59 UTC* @TonyStark please provide more info by giving an example image and the output with the --verbose option *By DarwinAwardWinner on 2014-11-06 07:59:30 UTC* By the way, you can easily generate a test file by converting a PNG to indexed colorspace in GIMP (Image -> Mode -> Indexed) and saving it. *By TonyStark on 2014-11-10 09:06:50 UTC* @josch ```--verbose``` give me below output ```bash D: input dpi = 96 x 96 D: input colorspace = RGBA D: width x height = 1597 x 2100 D: imgformat = PNG E: unsupported color space: RGBA ``` *By DarwinAwardWinner on 2014-11-10 09:11:21 UTC* Are you sure you're using a version of picopt from after #18 was merged? *By TonyStark on 2014-11-10 09:12:01 UTC* @DarwinAwardWinner no, let me try with that version.. *By TonyStark on 2014-11-10 09:18:28 UTC* @DarwinAwardWinner Thanx.... I update ```img2pdf.py``` and now works ```--verbose``` give me this output ```bash D: Reading test.png D: input dpi = 96 x 96 D: input colorspace = RGBA D: width x height = 1597 x 2100 D: imgformat = PNG D: Converting colorspace RGBA to RGB ``` *By josch on 2014-11-10 09:18:32 UTC* I released 0.1.3 which includes the fixes by @DarwinAwardWinner and some fix of mine. I'm able to convert the test input of @TonyStark with that version. Give it a try! *By josch on 2014-11-10 09:19:01 UTC* It's also on pypi if that matters. *By TonyStark on 2014-11-10 09:21:04 UTC* @josch Now Working with RGBA to RGB and P to RGB No any error... :+1: *By DarwinAwardWinner on 2014-11-10 09:21:19 UTC* I will say, though, having to convert indexed color to RGB is a little unfortunate, since it increases the file size a good bit. (Compare to imagemagick's "convert" utility converting png to pdf.) I wish I knew PIL well enough to write a special-case for indexed color inputs. *By TonyStark on 2014-11-10 09:24:21 UTC* @DarwinAwardWinner well ghostscript is best to compress pdf instead using imagemagick to compress png... test.png --> img2pdf --> out.pdf [1.2mb] ---> Ghostscript ---> out2.pdf [184kb] *By DarwinAwardWinner on 2014-11-10 09:27:47 UTC* Huh. I'll have to try that. *By josch on 2014-11-10 09:31:31 UTC* @DarwinAwardWinner imagemagick is able to convert indexed pngs to pdf at reduced size compared to img2pdf because it is lossy. The purpose of img2pdf is to not be lossy @TonyStark your ghostscript step is lossy, so no need to use img2pdf The limitation here is the image formats that PDF can read. The choices are JPEG, JP2 and Flate. The first two are lossy jpeg encodings (which img2pdf makes lossless if the input is a jpeg as well) and the last is just a zipped raw RGB, Grayscale or Black/White stream. To my knowledge, there is no option for palletted images there. So an image with indexed input image can only be converted to RGB to work with PDF. *By TonyStark on 2014-11-10 09:40:45 UTC* @josch ya its lossy output of ghostscript, but its good to readable *By josch on 2014-11-10 14:43:59 UTC* @TonyStark but if you want lossless in the first place, then what use is img2pdf for you? *By TonyStark on 2014-11-10 16:29:33 UTC* @josch im just giving example of size reducing.. *By josch on 2014-11-10 18:03:44 UTC* This seems to be solved. Closing.
josch closed this issue 2021-04-25 19:57:36 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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#16
No description provided.