1 2 3
my $photo_data = 'R0lGODlhAQABAJEAANnZ2f///////////yH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; my $photo = $mw->Photo(-data => $photo_data, -format => 'gif');
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
use MIME::Base64 qw/encode_base64 decode_base64/; # Bilddatei einlesen open (my $fh, $file_name) or die $!; binmode $fh; local ($/) = undef; # slurp # als Base64-kodiert in Variable speichern my $image_base64_data = encode_base64(<$fh>); close($fh) or die $!; # Base64-Daten als Bild speichern $image_base64_data = 'R0lGODlhAQABAJEAANnZ2f///////////yH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; open (my $fh, ">", $file_name) or die $!; binmode $fh; print $fh decode_base64($image_base64_data); close($fh) or die $!;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/usr/bin/perl use strict; use warnings; use Image::Magick; use MIME::Base64; # Create test Image my $img = Image::Magick->new(); $img->Set(size=>'20x20'); $img->ReadImage('xc:white'); $img->Annotate( text => '?', family => 'Arial', stroke => 'black', pointsize => 20, x => 4, y => 17 ); # serialize Image als base64 coded GIF my $data=encode_base64($img->ImageToBlob(magick => 'gif')); # test print print $data; # read Image from string my $img2=Image::Magick->new(); $img2->BlobToImage(decode_base64($data)); #test output $img2->Display();
1 2
my $image = $mw->Photo( -file => 'test.gif' ); my $image_data = encode_base64($image->data());
1 2 3
my $image_data = 'R0lGODlhBgAGAJEAANnZ2QAAAP///////yH5BAEAAAAALAAAAAAGAAYAAAINjA0HAEdwLCwMKIQfBQA7'; my $image = $mw->Photo(-data => $image_data, -format => 'gif'); $image->write('test.gif', -format => 'gif');
couldn't recognize image data at C:/Perl/site/lib/Tk/Image.pm line 21.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl use strict; use warnings; use Image::Magick; use MIME::Base64; my $data_in='R0lGODlhAQABAJEAANnZ2f///////////yH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; my $img=Image::Magick->new(); $img->BlobToImage(decode_base64($data_in)); my $data_out=encode_base64($img->ImageToBlob(magick => 'gif')); print "IN : $data_in\n"; print "OUT: $data_out\n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
use Tk; use MIME::Base64; my $mw = MainWindow->new(); my $image_data = 'R0lGODlhBgAGAJEAANnZ2QAAAP///////yH5BAEAAAAALAAAAAAGAAYAAAINjA0HAEdwLCwMKIQfBQA7'; my $image = $mw->Photo(-data => $image_data, -format => 'gif'); $image->write('test.gif', -format => 'gif'); print $image_data."\n"; my $image_new = $mw->Photo( -file => 'test.gif', -format => 'gif' ); my $image_data_new = encode_base64($image_new->data()); print $image_data_new; exit;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/usr/bin/perl use strict; use warnings; use Tk; use MIME::Base64; use Image::Magick; my $mw = MainWindow->new(); #my $image_data = 'R0lGODlhBgAGAJEAANnZ2QAAAP///////yH5BAEAAAAALAAAAAAGAAYAAAINjA0HAEdwLCwMKIQfBQA7'; my $image_data = 'R0lGODlhBgAGAPABAAAAAP///yH5BAEAAAEALAAAAAAGAAYAAAIJhB0Xq+y5YGQFADs='; print $image_data."\n"; my $image = $mw->Photo(-data => $image_data, -format => 'gif'); $image->write('test.gif', -format => 'gif'); my $image_new = $mw->Photo( -file => 'test.gif', -format => 'gif' ); my $img=Image::Magick->new(); $img->BlobToImage($image_new->data(-format => 'XPM')); #$img->Set(magick => 'gif'); #$img->Write('test2.gif'); my $image_data_new = encode_base64($img->ImageToBlob(magick => 'gif')); print $image_data_new; exit;