1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| <?php $window = new GtkWindow(); $window->set_size_request(240, 200); $window->connect_simple('destroy', array('Gtk','main_quit'));
$img = new GtkImage(); $img->drag_dest_set(Gtk::DEST_DEFAULT_ALL, array( array( 'text/uri-list', 0, 0)), Gdk::ACTION_COPY); $img->connect('drag-data-received', 'on_drop', $img);
// Set up gtkentry to get rotation angle
$vbox = new GtkVBox(); $button = new GtkButton('Imprint date'); $button->set_size_request(-1,24); $hbox = new GtkHBox(); $hbox->pack_start(new GtkLabel('Date: '), 0, 0); $date = date('Y-m-d'); $angle = new GtkEntry($date); $angle->set_size_request(100, -1); $button->connect('clicked', 'on_button', $angle); $hbox->pack_start($angle, 0, 0); $hbox->pack_start(new GtkLabel(' '), 0, 0); $hbox->pack_start($button, 0, 0); $vbox->pack_start($hbox, 0, 0); $vbox->pack_start($img);
$window->add($vbox); $window->show_all(); Gtk::main();
// process drop
function on_drop($widget, $context, $x, $y, $data, $info, $time, $img) { $uri_list = explode("\n",$data->data); global $img_file; $img_file = $uri_list[0]; $img_file = str_replace("file:///", "", $img_file);
$img_file = str_replace("\r", "", $img_file);
global $pixbuf; $pixbuf=GdkPixbuf::new_from_file($img_file); $width = $pixbuf->get_width(); $height = $pixbuf->get_height(); $img->set_from_pixbuf($pixbuf); global $window; $window->set_size_request($width, $height+24); }
function on_button($button, $angle_widget) { global $img_file; $date = $angle_widget->get_text(); // get the rotation angle
$im = imprint_date($img_file, $date); $pixbuf = GdkPixbuf::new_from_gd($im); // note 2
imagedestroy($im); $img = GtkImage::new_from_Pixbuf($pixbuf);
$dialog = new GtkDialog("imprint date on photo", null, Gtk::DIALOG_NO_SEPARATOR); // place the rotated image in a dialog
$dialog->vbox->pack_start($img); $dialog->show_all(); }
function imprint_date($img_file, $text) { list($img_width,$img_height, $img_type) = getimagesize($img_file); echo "img_size = $img_width x $img_height ($img_type)\n";
|