Hi there,
Is there a way to convert a PNG image in a KNIME table to base64 string?
Many thanks,
George
Hi there,
Is there a way to convert a PNG image in a KNIME table to base64 string?
Many thanks,
George
Hi George,
depending on your use-case also the "PNGs to Binary Objects" and "Binary Objects to PNGs" nodes might help. They are part of the "File Handling" Nodes which you can install via the KNIME Update-site.
Does this help? If not I will try to figure out how you can converts your PNGs to Base64 Strings (maybe JavaSnippet Node can help you).
Best,
Christian
Hi @christian.dietz,
I tried several options like:
Unfortunately, I failed all the time. I’d really appreciate your advice as Java is totally new for me.
Thanks a lot
Mike
Have you tried to use an external tool like R? There was a discussion with an Excel file:
Hi Mike, just wondering, did you eventually succeeded? I’m doing the same thing.
First converting PNG to binary, then encode the binary (InputStream format) with java snipped.
import java.util.Base64;
import java.io.*;
// system variables
public class JSnippet extends AbstractJSnippet {
// Fields for input columns
/** Input column: "Image" */
public InputStream c_Image;
// Fields for output columns
/** Output column: "Image_Base64" */
public String out_Base64;
// Your custom variables:
// expression start
public void snippet() throws TypeException, ColumnException, Abort {
// Enter your code here:
try {
int size = c_Image.available();
byte[ ] bytes = new byte[size];
c_Image.read(bytes);
out_Base64 = new String(Base64.getEncoder().encode(bytes));
}
catch(IOException ie) {
ie.printStackTrace();
}
Pierre
Hi Pierre,
yes, I did to some extend. Back then I did not further continued due to other priorities. I managed to add an image generated during the workflow as an attachment. Where I did not continued was about displaying it in the email as such.
Here are the results from back then:
Best
Mike
fyi: There’s a Base64 encoder and decode node in newer versions of Palladian now:
–Philipp