You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way where we can merge the PIL images to one single image for multipage pdf ?
I see, in parsers.py function parse_buffer_to_jpeg, we convert the hex to PIL image array using Image.open( .. ) by splitting on \xff\d9 which is great but when I printed the buffer I saw the following -
Any jpeg file buffer hex starts with \xff\xd8 (which marks the start) and \x\ff\d9 (which marks the end). But when there is a multipage pdf, we do have something like this in middle -\x\ff\d9\xff\xd8 (combination of ending of page1 hex with starting of page2 hex). I tried removing it and replaced it with some random hex code but It didn't work. The Pillow image is created but when i try to save it, it fails. Am I missing something here ?
Can we have a solution/workaround for this as we need this ASAP?
The reason for this ask is because, we want to concatenate all the images to one single image and pass it to another system (which is consuming a lot of memory in RAM)
Merge images to one single image logic if you're interested to debug why it is consuming a lot of memory!
def merge(pil_images):
widths, heights = zip(*(i.size for i in pil_images))
total_width = max(widths)
max_height = sum(heights) + (len(pil_images) -1)* 10
merged_pil_image = Image.new('RGB', (total_width, max_height))
x_offset = 0
for im in pil_images:
merged_pil_image.paste(im, (0, x_offset))
x_offset += im.height +10
return merged_pil_image
The text was updated successfully, but these errors were encountered:
Hi Edouard,
Is there a way where we can merge the PIL images to one single image for multipage pdf ?
I see, in
parsers.py
functionparse_buffer_to_jpeg
, we convert the hex to PIL image array using Image.open( .. ) by splitting on \xff\d9 which is great but when I printed the buffer I saw the following -Any jpeg file buffer hex starts with \xff\xd8 (which marks the start) and \x\ff\d9 (which marks the end). But when there is a multipage pdf, we do have something like this in middle -\x\ff\d9\xff\xd8 (combination of ending of page1 hex with starting of page2 hex). I tried removing it and replaced it with some random hex code but It didn't work. The Pillow image is created but when i try to save it, it fails. Am I missing something here ?
Can we have a solution/workaround for this as we need this ASAP?
The reason for this ask is because, we want to concatenate all the images to one single image and pass it to another system (which is consuming a lot of memory in RAM)
Merge images to one single image logic if you're interested to debug why it is consuming a lot of memory!
The text was updated successfully, but these errors were encountered: