How to convert WEBP to PDF without increasing size? #91

Closed
opened 3 years ago by josch · 0 comments
josch commented 3 years ago
Owner

By Bob on 2021-03-07T11:03:59.556Z

Hello,
I would like to convert a list of WEBP images to a PDF.
When do it with img2pdf, the size is multiplied by 10!

Is there a way to have a PDF file using the WEBP images without a convertion to PNG?


By josch on 2021-03-07T11:40:16.986Z


I'm actually surprised that img2pdf is able to use webp images an input without throwing any errors! This is probably because PIL has no problem with the webp format.

I'm not surprised that the file size is multiplied by 10. Since the webp format is not jpeg and not png, the image has to re-encoded and to not loose any information, img2pdf will encode the image to png which for photos lets the file size explode.

I see two ways to achieve what you want :

  1. avoid re-encoding: this is only possible if the pdf file format supports webp images, which it does not
  2. with re-encoding (and lossless): convert your images into a lossless format of your choice before passing it to img2pdf (png is lossless but a terrible choice for photos)
  3. with re-encoding (and lossy): convert your images into a lossy format like jpeg before passing them to img2pdf

The best option would be the first but I do not see any support of webp images in the pdf standard. I'll leave this bug open because support for it might be added in the future though I fear if any new image format is added to pdf, then it might be AVIF instead because that one outperforms webp.

img2pdf will never support option three out-of-the-box because img2pdf will always be lossless. So if you are find with the conversion being lossy, then you have to do the conversion yourself before passing the files to img2pdf.


By Bob on 2021-03-10T14:01:52.899Z


You said:

avoid re-encoding: this is only possible if the pdf file format supports webp images, which it does not

OK, that's the answer I needed. I looked in the internet but it wasn't that clear.

Thank you for your answer!


By Bob on 2021-03-10T14:01:53.148Z


Status changed to closed

*By Bob on 2021-03-07T11:03:59.556Z* Hello, I would like to convert a list of WEBP images to a PDF. When do it with `img2pdf`, the size is multiplied by 10! Is there a way to have a PDF file using the WEBP images without a convertion to PNG? --- *By josch on 2021-03-07T11:40:16.986Z* --- I'm actually surprised that img2pdf is able to use webp images an input without throwing any errors! This is probably because PIL has no problem with the webp format. I'm not surprised that the file size is multiplied by 10. Since the webp format is not jpeg and not png, the image has to re-encoded and to not loose any information, img2pdf will encode the image to png which for photos lets the file size explode. I see two ways to achieve what you want : 1. avoid re-encoding: this is only possible if the pdf file format supports webp images, which it does not 2. with re-encoding (and lossless): convert your images into a lossless format of your choice before passing it to img2pdf (png is lossless but a terrible choice for photos) 3. with re-encoding (and lossy): convert your images into a lossy format like jpeg before passing them to img2pdf The best option would be the first but I do not see any support of webp images in the pdf standard. I'll leave this bug open because support for it might be added in the future though I fear if any new image format is added to pdf, then it might be AVIF instead because that one outperforms webp. img2pdf will never support option three out-of-the-box because img2pdf will always be lossless. So if you are find with the conversion being lossy, then you have to do the conversion yourself before passing the files to img2pdf. --- *By Bob on 2021-03-10T14:01:52.899Z* --- You said: > avoid re-encoding: this is only possible if the pdf file format supports webp images, which it does not OK, that's the answer I needed. I looked in the internet but it wasn't that clear. Thank you for your answer! --- *By Bob on 2021-03-10T14:01:53.148Z* --- Status changed to closed
josch closed this issue 3 years ago
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 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#91
Loading…
There is no content yet.