What's the proper way to read an image from the hard drive, for example to base64 encode it?
I usually do something along the lines of...
Sometimes I join("\n") or join("")... I usually try one or the other and test it out and if the image is corrupted when rewriting it to a file after then I know it was the opposite one.
Is there a better way of reading an image? Do I need to chomp it or worry about newlines, or does the binary data all come as one line to where I could just do
-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
I usually do something along the lines of...
Code:
use MIME::Base64 qw(encode_base64);
open (READ, "something.gif");
binmode READ;
my @data = <READ>;
close (READ);
chomp @data;
my $bin = join("",@data);
my $base64 = encode_base64 ($bin);
# then i.e. feed it to Tk::Photo
$mw->Photo (-data => $base64, -format => 'GIF');
Sometimes I join("\n") or join("")... I usually try one or the other and test it out and if the image is corrupted when rewriting it to a file after then I know it was the opposite one.
Is there a better way of reading an image? Do I need to chomp it or worry about newlines, or does the binary data all come as one line to where I could just do
Code:
open (DATA, "something.gif");
binmode DATA;
$bin = <DATA>;
close (DATA);
$base64 = encode_base64($bin);
-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog