How do I encode gif image into Base64 string?

So I’m trying to send a gif image to our server to get a QR code. Our server generally takes base64 strings but I don’t really have any idea as to how to achieve this. I’ve used ofxCrypto and successfully encoded images, but not gif. It would seem that, from experience, ofxCrypto only encodes from ofBuffer / string. Is there a way to load a gif image into ofBuffer?
Base64 strings from individual frames show no similarity with that of the entire gif file either, as tested on an online base64 encoder.
I’ve searched all over this forum, github and the examples with no results. Does anyone have any ideas? I apologize in advance if I missed some obvious solutions.
Thanks,
Kaun

I have not tested this, but i think that you can pass an ofImage to a ofBuffer this way:

ofImage imagen;
ofBuffer buffer;

imagen.load("filename.gif");
imagen.save(buffer);

I just added an example of how to do this with ofxIO. ofxIO also allows several options, including url-safe base64 encoding, etc.

@pandereto your solution actually converts the gif to raw pixels, and then re-encodes the raw pixels to JPEG before placing the JPEG bytes in a buffer.

Also, for what it’s worth, here’s an example of ofxIO in action uploading encoded images:

Thanks, i didn’t know that

Ah thanks everyone. I’ve been busy with the canon SDK lately so I couldn’t try the suggestions yet. But I’ll definitely try it out when I have time and maybe tell you how it went. Thanks a lot. :slight_smile:

ofxIO is really easy to use! Works like a charm. Thanks everyone.