Way to base 64 encode images

hi all,
I am figuring out a way to base64 encode images . please help. I think base64 function is for text and not for images

You can use the Binary to Document Snap to base64-encode a binary stream into a document with a property that contains the encoded value.

Long before the Binary to Document snap was developed and available, I used a Script snap. I should look at the Binary to Document snap to see if it improves my pipeline, but if that snap doesn’t serve your purpose, here’s a snippet of Python that may help. You need to import base64.
(note: this code is 3 years old, and I’m not a Pyhton guru, so certain code & exception handling may be improved)

            with open(filepath2, "rb") as f:
                bytes = ""
                byte = f.read(1)
                while byte != b"":
                    bytes = bytes + byte
                    byte = f.read(1)
                if byte != b"":
                    bytes = bytes + byte
                output = base64.b64encode(bytes)
        except Exception as e:
            map = java.util.HashMap()
            map.put('Exception',str(e.errno) + ": " + e.strerror)

tried this but i see difference in encoded values from using snaplogic functions and different online encoders available. may be a lot other things are getting encoded apart from image data. ie $content availble from file redaer has much more data than the actual image

Hope this helps