Gtk3::ImageView(3)

πŸ¦‹ Gtk3::ImageView(3) β€” the Perl doc page, bestie edition

okay so this is a User Contributed Perl Documentation page for Gtk3::ImageView(3), and I'm gonna walk you through it like we're on FaceTime at 1am πŸ’–


πŸ’… NAME

Gtk3::ImageView β€” an image viewer widget for Gtk3. that's it, that's the vibe πŸŽ€


✨ VERSION

9 β€” yes queen, version nine πŸ‘‘


🌸 SYNOPSIS

here's the lil starter pack, copy it exactly:

use Gtk3::ImageView;
Gtk3->init;

$window = Gtk3::Window->new();

$view = Gtk3::ImageView->new;
$view->set_pixbuf($pixbuf, TRUE);
$window->add($view);

$window->show_all;

like… window, view, pixbuf, show it. slay 🫢


🧚 DESCRIPTION

so the Gtk3::ImageView widget lets the user zoom, pan, and select the specified image, and it gives you hooks so you can build extra tools on top β€” like a painter, for example 🎨 literally choose your own adventure.

Gtk3::ImageView is a Gtk3 port of Gtk2::ImageView. glow-up era 🌈

and if you wanna discuss Gtk3::ImageView or gtk3-perl, ask questions, or flame/praise the authors (😭 not the flame part), come join gtk-perl-list@gnome.org at lists.gnome.org. it's giving community 🫢


⭐ SUBROUTINES/METHODS

πŸŽ€ $view->set_pixbuf( $pixbuf, $zoom_to_fit )

defines the image to view, periodt. the optional zoom_to_fit parameter says whether to zoom to fit the image or not β€” that's the whole thing πŸ’–

πŸŽ€ $view->get_pixbuf

returns the image currently being viewed. the main character, returned to you πŸ“Έ

πŸŽ€ $view->get_pixbuf_size

returns a hash containing the size of the current image, in width and height keys. dimensions, bestie πŸ¦‹

πŸŽ€ $view->set_zoom($zoom)

specifies the zoom level πŸ”

πŸŽ€ $view->get_zoom

returns the current zoom level πŸ”

πŸŽ€ $view->set_zoom_to_fit($zoom_to_fit, $limit)

specifies whether to zoom to fit or not. if limit is defined, such automatic zoom will not zoom more than it. if the limit is undefined, the previously set limit is used β€” and initially it's unlimited 🌈

πŸŽ€ $view->zoom_to_box( $box, $additional_factor )

specifies a box to zoom to, including an additional zoom factor πŸ“¦βœ¨

πŸŽ€ $view->zoom_to_selection($context_factor)

zooms to the current selection, plus an additional zoom factor (yes, the spelling in the original is addition, I'm keeping it 🫢). it's a shortcut for:

$view->zoom_to_box( $view->get_selection, $context_factor );

πŸŽ€ $view->get_zoom_to_fit

returns whether the view is currently zoom to fit or not βœ…

πŸŽ€ $view->zoom_in

increases the current zoom by "zoom-step" times (defaults to 2) πŸ”ŽπŸ”₯

πŸŽ€ $view->zoom_out

decreases the current zoom by "zoom-step" times (defaults to 2) πŸ”ŽπŸ’€

πŸŽ€ $view->zoom_to_fit

shortcut for:

$view->set_zoom_to_fit(TRUE);

πŸŽ€ $view->set_fitting( $value )

shortcut for:

$view->set_zoom_to_fit($value, 1);

which means that it won't stretch a small image to a large window πŸ–ΌοΈ no catfishing the pixels. it's provided (despite the ambiguous name β€” yes we know, the name is doing the most πŸ™ˆ) for compatibility with Gtk2::ImageView.

πŸŽ€ $view->set_offset( $x, $y )

set the current view offset (i.e. pan position) πŸ•ΉοΈ

πŸŽ€ $view->set_offset

returns the current view offset (i.e. pan position). nope, that's genuinely what the page says β€” same name as the one above, but this one returns it. I'm just the messenger πŸ’…

πŸŽ€ $view->get_viewport

returns a hash containing the position and size of the current viewport πŸͺŸ

πŸŽ€ $view->set_tool

set the current tool (i.e. mode) β€” an object of a subclass of "Gtk3::ImageView::Tool" πŸ› οΈ

here are some known subclasses of it:

  • "Gtk3::ImageView::Tool::Dragger" lets the image be dragged when zoomed 🀏
  • "Gtk3::ImageView::Tool::Selector" lets the user select a rectangular area of the image πŸ”²
  • "Gtk3::ImageView::Tool::SelectorDragger" selects or drags with different mouse buttons πŸ–±οΈ
⚠️ don't rely too much on how Tool currently interacts with ImageView. it's giving "situationship" β€” don't get attached 😭

πŸŽ€ $view->get_tool

returns the current tool (i.e. mode) πŸ› οΈ

πŸŽ€ $view->set_selection($selection)

set the current selection as a hash of position and size βœ‚οΈ

πŸŽ€ $view->get_selection

returns the current selection as a hash of position and size βœ‚οΈ

πŸŽ€ $view->set_resolution_ratio($ratio)

set the ratio of the resolutions in the x and y directions, letting images with non-square pixels be correctly displayed πŸ“ kinda iconic of it honestly

πŸŽ€ $view->get_resolution_ratio

returns the current resolution ratio πŸ“

πŸŽ€ $view->set_interpolation

the interpolation method to use, from "cairo_filter_t" type (link in the original: https://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-filter-t). possible values are lowercase strings like "nearest" πŸ”€. to use different interpolation depending on zoom, set it in the "zoom-changed" signal πŸ“‘

πŸŽ€ $view->get_interpolation

returns the current interpolation method πŸ”€


🌟 DIAGNOSTICS

(empty in the original β€” nothing listed here, bestie. we move 🫢)


🌟 CONFIGURATION AND ENVIRONMENT

(also empty. no config, no env vars. minimalism ✨)


🌟 DEPENDENCIES

(nothing listed either. wild, I know πŸ’€)


πŸ’œ INCOMPATIBILITIES

🧡 Porting from Gtk2::ImageView

okay listen, if you're coming from the Gtk2 era, here's the whole lore drop πŸ“–:

  • set_from_pixbuf() was renamed to set_pixbuf(), and now its second argument means zoom_to_fit() instead of set_fitting() πŸ”
  • set_fitting(TRUE) used to be the default; now you need to call it explicitly if you want that behavior. however, once it's called, new calls to set_from_pixbuf() won't reset it β€” see set_zoom_to_fit() for more details πŸ™ƒ (and yeah, the original sentence ends with two periods. leaving it exactly as it is 🫑)
  • drag and drop can now be triggered by subscribing to the "dnd-start" signal, and calling "$view->drag_begin_with_coordinates()" from the handler. drag_source_set() won't work 🚫
  • the "Gtk2::ImageView::ScrollWin" replacement is not yet implemented 😭 patience, bestie
  • set_transp() is now available through CSS instead (link in the original: https://developer.gnome.org/gtk3/stable/chap-css-overview.html), e.g. via:
.imageview.transparent {
    background-image: url('checkers.svg');
}

πŸ’€ BUGS AND LIMITATIONS

and I quote: this should be rewritten in C, and Perl bindings should be provided via Glib Object Introspection πŸ’€ the author said "we need a rewrite" and honestly? respect for the honesty, no cap πŸ”₯


πŸ‘‘ AUTHOR

  • Jeffrey Ratcliffe, <jffry@posteo.net> 🫢
  • Alexey Sokolov <sokolov@google.com> 🫢

Copyright (C) 2018--2020 by Jeffrey Ratcliffe

Copyright (C) 2020 by Google LLC

modelled after the GtkImageView C widget by Bjârn Lindqvist <bjourne@gmail.com> 🌸

this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available ✨


aaaand that's the whole page, bestie πŸŽ€ this was perl v5.42.0, dated 2024-10-13, and it's the Gtk3::ImageView(3) manual page β€” ily, go zoom some pixels πŸ’–πŸ¦‹πŸŒˆ

πŸ“¦ where this page comes from