List Info

Thread: Resizing xpm data?




Resizing xpm data?
user name
2007-02-19 21:52:35
Hi all,

I'm using xpm's for the images for a bunch of action
buttons. This
works quite nicely.

These action buttons also have corresponding entries in a
menu (in
case the action buttons have been hidden) and I'd like to
put the same
images in next to their corresponding menu entry.
Unfortunately, other
than actually making an XPM file that defines a smaller
image, I can't
figure out how to 'resize' the images.

The images are created like so:

$img = Gtk2::Image->new;
$img->set_from_file("/path/to/image.xpm");

Is there anything I can do from there to make a resized
version, or do
I have to follow a different path there?

MB
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Resizing xpm data?
country flaguser name
Australia
2007-02-19 22:28:18
Matthew Braid wrote:

> Hi all,
>
> I'm using xpm's for the images for a bunch of action
buttons. This
> works quite nicely.
>
> These action buttons also have corresponding entries in
a menu (in
> case the action buttons have been hidden) and I'd like
to put the same
> images in next to their corresponding menu entry.
Unfortunately, other
> than actually making an XPM file that defines a smaller
image, I can't
> figure out how to 'resize' the images.
>
> The images are created like so:
>
> $img = Gtk2::Image->new;
>
$img->set_from_file("/path/to/image.xpm");
>
> Is there anything I can do from there to make a resized
version, or do
> I have to follow a different path there?

Firstly, I don't do a lot of work with images, so this
mightn't be the 
best way to do it
Gtk2::Gdk::Pixbuf has image scaling support, eg:

$pixbuf = $pixbuf->scale_simple(
   $width,
   $height,
   'nearest'
);

I don't know if you can make a Gtk2::Gdk::Pixbuf directly
from an xpm - 
never tried, probably works, but I'm sure there's a way.
Once you've got 
your scaled image, you can go:

$img = Gtk2::Image->new_from_pixbuf ( $pixbuf );

-- 
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasaknusconsulting.com.au
website: http://www.nusconsult
ing.com.au
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Resizing xpm data?
user name
2007-02-19 22:47:42
On 2/20/07, Daniel Kasak <dkasaknusconsulting.com.au>
wrote:
> Firstly, I don't do a lot of work with images, so this
mightn't be the
> best way to do it
> Gtk2::Gdk::Pixbuf has image scaling support, eg:
>
> $pixbuf = $pixbuf->scale_simple(
>    $width,
>    $height,
>    'nearest'
> );
>
> I don't know if you can make a Gtk2::Gdk::Pixbuf
directly from an xpm -
> never tried, probably works, but I'm sure there's a
way. Once you've got
> your scaled image, you can go:
>
> $img = Gtk2::Image->new_from_pixbuf ( $pixbuf );

Aha!

$img = Gtk2::Image->new;
$img->set_from_file("/path/to/file.xpm");
$img->set_from_pixbuf($img->get_pixbuf->scale_simpl
e(16, 16, "hyper"));

Does exactly what I need  Thanks for
the help there. I think my main
problem is trying to resolve all the 'bits' of an image
(image/pixbuf/etc) that I need to know.

MB
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Resizing xpm data?
country flaguser name
United States
2007-02-20 14:50:57
On Feb 19, 2007, at 10:52 PM, Matthew Braid wrote:

> Is there anything I can do from there to make a resized
version, or do
> I have to follow a different path there?

TIMTOWTDI:

my $xpm_path = "/path/to/image.xpm";

# load directly
my $img = Gtk2::Image->new_from_file ($xpm_path);

# equivalent to Gtk2::Image::new_from_file()
my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file
($xpm_path);
$img->set_from_pixbuf ($pixbuf);

# load then scale (e.g. if you need both regular and small)
my $small_pixbuf = $pixbuf->scale_simple ($dest_width,
$dest_height,  
'bilinear');
$img->set_from_pixbuf ($small_pixbuf);

# scale on load
my $other_small_pixbuf =
     Gtk2::Gdk::Pixbuf->new_from_file_at_size ($xpm_path,
 
$dest_width, $dest_height);
$img->set_from_pixbuf ($other_small_pixbuf);


--
I hate to break it to you, but magic data pixies don't
exist.
   -- Simon Cozens


_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )