Skip to content

Instantly share code, notes, and snippets.

@Downes
Created December 2, 2018 21:07
Show Gist options
  • Save Downes/aaf82d5e1097ac46e3dd79b2c340bc09 to your computer and use it in GitHub Desktop.
Save Downes/aaf82d5e1097ac46e3dd79b2c340bc09 to your computer and use it in GitHub Desktop.
Encoding an image into Base64 in Perl for gRSShopper
if ($filerecord->{file_dirname} eq "image/png") {
my $imgfilename = $Site->{st_urlf}.$filerecord->{file_dirname};
use File::Slurp;
use MIME::Base64 qw|encode_base64|;
$imagestr = encode_base64( read_file( $imgfilename ) );
$imagestr =~ s/\n//g;$imagestr =~ s/\n//g; # because they get inserted somehow and Badgr chokes on them
$imagestr = "data:image/png;base64,".$imagestr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment