Re: Size of a GtkImage
| From: | Breizh Micro Services | Date: | Sat, 11 Feb 2006 08:30:53 +0000 |
| Subject: | Re: Size of a GtkImage | ||
| References: | 1 2 3 4 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-6717@lists.php.net to get a copy of this message | ||
Ok, my last code :
It is an application which can zoom in and zoom out an image. I will add this week some button to open file and more.
<?php
$zoom = 1;
function zoom($scale){
//same zoom on width and on height
global $image,$original_pixbuf;
$height = $original_pixbuf->get_height();
$width = $original_pixbuf->get_width();
$new_width = $width*$scale;
$new_height = $height*$scale;
$new_pixbuf = $original_pixbuf->scale_simple($new_width,$new_height,'GDK_INTERP_BILINEAR');$image->set_from_pixbuf($new_pixbuf); } function zoom_in(){ global $zoom; $zoom = $zoom * 2; zoom($zoom); } function zoom_out(){ global $zoom; $zoom = $zoom / 2; zoom($zoom); } $window = new GtkWindow(); $window->set_title('PHP Test'); $window->connect_simple('destroy', array('gtk', 'main_quit')); $main = new GtkTable(1,2); $main->show(); $image = GtkImage::new_from_file("test.jpg"); $original_pixbuf = $image->get_pixbuf(); $scrolledWindow = new GtkScrolledWindow(); $scrolledWindow->add_with_viewport($image); $main->attach($scrolledWindow,0,1,0,1); $Vbox = new GtkVbox(); $Vbox->show(); $Vbox->set_spacing(10); $main->attach($Vbox,1,2,0,1,'GTK_FILL','GTK_SHRINK'); $button_zoom_in = new GtkButton("Zoom +"); $button_zoom_in->connect('clicked','zoom_in'); $Vbox->add($button_zoom_in); $button_zoom_out = new GtkButton("Zoom -"); $button_zoom_out->connect('clicked','zoom_out'); $Vbox->add($button_zoom_out); $window->add($main); $window->set_size_request(800,600); $window->show_all(); Gtk::main(); ?> Is it ok for you ? :) Breizh. Ron Tarrant a écrit :
Hi Breizh, Could you post the entire example, please? In the code you posted, I didn't see any zoom controls or callbacks. -Ron T.For those who want to make zoom in or out, this is an example :