Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
Last active August 19, 2016 15:46
Show Gist options
  • Save vadimkantorov/ea85b070f99235644baf to your computer and use it in GitHub Desktop.
Save vadimkantorov/ea85b070f99235644baf to your computer and use it in GitHub Desktop.
A Matlab snippet to output Base64-encoded img's to be used for HTML visualizations
f = figure();
plot(1:10, 1:10);
rgbData = figToImStream('figHandle', f, 'imageFormat', 'jpg', 'outputType', 'uint8');
%print(f, '-djpg', '/tmp/vis.jpg'); rgbData = fread(fopen('/tmp/vis.jpg'), 'uint8=>uint8'); % replace previous line by this line in case of failure
fprintf('<img src="data:image/jpeg;base64,%s" />', char(org.apache.commons.codec.binary.Base64.encodeBase64(rgbData))');
close(f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment