Hi all,
I try to convert a jpeg file to Base64 to integrate an image in a html page to send by mail ;
I try with ImageMagick but don't work... Anyone have an idea ???
Thanks.
Encode a jpg file -> Base64
Re: Encode a jpg file -> Base64
If you have the Scripting Module you could do it with a script like this;
This script converts the image to Base64 and set a private data tag "Base64Image" which contains the Base64 string.
Code: Select all
// Is invoked each time a new job arrives in one of the input folders for the flow element.
// The newly arrived job is passed as the second parameter.
function jobArrived( s : Switch, job : Job )
{
// Read contents of incoming job in ANSI codec
var imgContents = File.read(job.getPath(), "ANSI");
// Convert to Base64
var imgToBase64 = new ByteArray(imgContents, "ANSI").convertTo("Base64");
// Set private data tag "Base64Image" to Base64 string
job.setPrivateData("Base64Image", imgToBase64.toString("UTF-8"));
// Send to outgoing connection
job.sendToSingle(job.getPath());
}
Re: Encode a jpg file -> Base64
It is a bit safer (because there is no encoding involving) and certainly more efficient to use
than to do it in two steps by reading the file as a string and then convert that to a ByteArray.
Code: Select all
var imgContents = File.readByteArray( job.getPath());
Re: Encode a jpg file -> Base64
That is a much cleaner solution Freddy, thank you for mentioning it!freddyp wrote: ↑Mon Oct 07, 2019 8:59 am It is a bit safer (because there is no encoding involving) and certainly more efficient to usethan to do it in two steps by reading the file as a string and then convert that to a ByteArray.Code: Select all
var imgContents = File.readByteArray( job.getPath());