Possibility to provide PIL.Image.Image
objects as input? #115
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?
I sometimes have to pre-process the images I convert to PDF with img2pdf. Currently, I save the
PIL.Image.Image
object into anio.BytesIO
stream and then pass it to img2pdf. However, I guess this adds an avoidable layer of save/open, since img2pdf also uses Pillow internally. Would it be possible for img2pdf to directly accept PIL images as input?I don't see how this can be possible. Not all input images are read into a PIL object. JPEG images, for example, are copied into the PDF as they are and you cannot do that if you just give the PIL object to img2pdf.
I see. Maybe img2pdf could detect the format and convert to a byte stream only if necessary, like in the case of JPEG?
If you think this does not fit the design of img2pdf, feel free to close the issue.
But that would be a lossy operation.
Why? Consider I have a PIL image that was created from scratch, for instance. Where is the quality loss?And if I open a JPEG file with PIL and saved it to JPEG again, it should be the exact same data, right?Because you were talking about a JPEG. If you open a JPEG with PIL and then hand that JPEG to img2pdf, then you cannot retrieve the original file just from the PIL object and storing that PIL object as JPEG is lossy.
Ookay, surprising this is lossy. I'll test it.
Indeed. It is. I would have expected it to be lossless, if no modifications have taken place.