Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode base64 and turn it back into an image in perl

Tags:

base64

perl

I have a variable $photo (huge string that has been base64 encoded) that I believe I need to decode it using MIME::Base64 with something like this:

my $decoded= MIME::Base64::decode_base64($photo);

now after that how to I make $decoded back into a jpg as it was before?

like image 363
BluGeni Avatar asked Dec 27 '22 04:12

BluGeni


1 Answers

You can write it to a file just like you can write any other data. You need to set the filehandle to binary, though.

my $decoded= MIME::Base64::decode_base64($photo);
open my $fh, '>', 'photo.jpg' or die $!;
binmode $fh;
print $fh $decoded;
close $fh
like image 88
simbabque Avatar answered Feb 19 '23 11:02

simbabque