4

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?

BluGeni
  • 3,378
  • 8
  • 36
  • 64
  • 1
    After decoding, the content of `$decoded` should be valid jpg data, assuming that `$photo` contained a properly-Base64-encoded jpg image to start with. Are you asking how to write that data to a file? Or do you mean something else? – Dave Sherohman May 07 '13 at 18:03
  • yes Im asking how to write that to a file. – BluGeni May 07 '13 at 18:17

1 Answers1

11

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
simbabque
  • 53,749
  • 8
  • 73
  • 136