Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to resize base64 code representing the image?

I am using power autoamte to convert an image in base64, and then I put this code in html.
Here is what I do:

  1. I convert the original image to base64
  2. I put this code in the html content in the <img src='myBase64'>
    tag.
  3. I convert the html to pdf format

Everything is fine, but when my html file reaches more than 2 mb my flow stops working. This is the limit for this conversion operation.

My question is:
Is it possible to resize the base64 code? I know there are external connectors resize images like Encodian, but I don’t want to use them.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I searched on the internet, but without much results.

Thank you in advance

>Solution :

Yes, it is possible to resize base64 code representing the image. There are a few ways to do this:

  1. Use an online tool like Base64 Image Decoder to resize the base64 code.

  2. Use a program like ImageMagick to resize the base64 code.

  3. Use a script like the following to resize the base64 code:

#!/usr/bin/env python

import base64

from PIL import Image

def resize_base64_code(base64_code, width, height):
    img = Image.open(io.BytesIO(base64.b64decode(base64_code)))
    img = img.resize((width, height), Image.ANTIALIAS)
    return base64.b64encode(img.tobytes()).decode()

if __name__ == '__main__':
    base64_code = '...' # your base64 code here
    width = 200
    height = 200
    resized_base64_code = resize_base64_code(base64_code, width, height)
    print(resized_base64_code)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading