RE: base64 encoded images as styles



This is just something I was looking at, in case I wanted
to put small base64 encoded images in a self-contained
script.  
Is it somehow possible to setup a style, with the data
from the base64 encoded string?
If I write the png out to a tmp file, and have a .gtkrc
file to load, it works, but I would like to avoid making
a temp file.

#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 -init;
use MIME::Base64 qw( decode_base64 );

#a base64 encoded small png
my $bg64 =
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAAYCAIAAAC0rgCNAAAABmJLR0QA+QD4A
OZO2ex2AAAACXBI
WXMAAAsOAAALDgFAvuFBAAAAB3RJTUUH1AUICxwUuNc1xwAAAENJREFUeNptya
ENgEAQAMHP7vWv
6IdgqICcJQR3oYXnEQgMdqYt89RG31ofN/uxclUhooEKSiBEvP5zGuDnIlUnmf
kAnDYTH2CoCOEA
AAAASUVORK5CYII=';

my $image_data = decode_base64($bg64);

# if you want to create the file bg.png
#  open (FH,"> bg.png");
#  print FH  $image_data ;
#  close FH;

my $loader = Gtk2::Gdk::PixbufLoader->new;
  $loader->write ($image_data);
    $loader->close;
  my $pixbuf = $loader->get_pixbuf;

my $image = Gtk2::Image->new_from_pixbuf ($pixbuf);
my $pb = $image->get_pixbuf;


#this works when the style string below
#is put in ./gtkrc
#Gtk2::Rc->parse ('gtkrc');

#this won't work with any variable
#=head
Gtk2::Rc->parse_string(<<__);
style "default"
{
 bg_pixmap[NORMAL] = $image_data

obviously the syntax assumes for you to write 
bg_pixmap[NORMAL] = "bg.png"
and not base64-encoded data.

Whether or not Gtk allows inlining of file in its "gtkrc" config - I don't
know, but may be Gtk people will answer?

Also, if all else fails, you can always call functions that will draw your
pixmap on your window.

}

class "*" style "default"
__
#=cut

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { exit;});
$window->set_border_width(5);
$window->set_position('center_always');
$window->set_default_size(500,500);
$window->show();

Gtk2->main();
#######################################################
__END__


Vadim.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]