Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Try creating a new (empty) image of the required size and then use cairo to fill it with the desired contents. The following link may help you (though it is in C and not perl, but the API is the same):


On Thu, Oct 26, 2017 at 11:18 AM, Les Trol <lestrol123 gmx com> wrote:
I'm implementing a spec in which an image is displayed in a Gtk2::Textview. Simple enough to do, but the spec requires optional extras, such as displaying padding around the image and detecting clicks on it.
Taking one problem at a time:
1. Sometimes the image must be displayed its original size. Sometimes it must be its original size, but surrounded by some empty 'padding'.
The script below is the closest I've been able to get so far. It uses Gtk2::Gdk::Pixbuf->scale to create the 'padding'.
However, the 'padding' is not empty space, as I'd hoped, but a blur of pixels from the edges of the original image. I see the same effect for many different images in different sizes (such as this cat image: - I see )
Is there a simple way to remove the blur, or does this call for a different approach entirely?
package scaleme;
use strict;
use diagnostics;
use warnings;
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
# Display this image
my $path = 'change_this_directory/cat.bmp';
# Open a Gtk2 window with a Gtk2::TextView
my $window = Gtk2::Window->new('toplevel');
$window->set_default_size(800, 600);
$window->signal_connect('delete-event' => sub {
my $frame = Gtk2::Frame->new();
my $scrollWin = Gtk2::ScrolledWindow->new(undef, undef);
$scrollWin->set_policy('automatic', 'automatic');     
my $textView = Gtk2::TextView->new;
if (-e $path) {
    # Display a photo of a cat face
    my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
    my $buffer = $textView->get_buffer();
    # Make the overall image 20% bigger, but the cat's face is its
    #   original size (and centred in the middle)
    my $factor = 0.2;   
    my $w = $pixbuf->get_width();
    my $h = $pixbuf->get_height();
    my $pixbuf2 = Gtk2::Gdk::Pixbuf->new(
        ($w * (1 + $factor)),
        ($h * (1 + $factor)),
        # $dest
        # $destx, $desty
        # $dest_width, $dest_height
        ($w * (1 + $factor)),
        ($h * (1 + $factor)),
        # $offset_x, $offset_y
        ($w * ($factor / 2)),
        ($h * ($factor / 2)),
        # $scale_x, $scale_y
        # $interp_type

gtk-perl-list mailing list
gtk-perl-list gnome org

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