Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: PerlMagick Gtk2::Gdk::Pixbuf

by renegadex (Beadle)
on Jul 22, 2008 at 00:25 UTC ( #699193=note: print w/replies, xml ) Need Help??


in reply to Re: PerlMagick Gtk2::Gdk::Pixbuf
in thread PerlMagick Gtk2::Gdk::Pixbuf

i would like to share the program that i did. its messy but you can see how i did what zentara showed us.
#!/usr/bin/perl -w #image data transfer from imagemagick to pixbuf!!! yey! use Gtk2 '-init'; use Image::Magick; my $pimage; my $pimage2; my $image; my $image2; my $canvas; my $pixbufloader; my $pixbuf; #sub load; my $window = Gtk2::Window->new; $window->signal_connect(destroy=>sub{Gtk2->main_quit;}); $window->set_size_request(1000,600); my $vbox = Gtk2::VBox->new; $window->add($vbox); #my $pixbuf = Gtk2::Gdk::Pixbuf->new(undef); our $image1 = Gtk2::Image->new; my $swin = Gtk2::ScrolledWindow->new; $swin->add_with_viewport($image1); $vbox->pack_start($swin,1,1,0); my $button = Gtk2::Button->new('LOAD'); $button->signal_connect('clicked',\&load); $vbox->pack_start($button,0,1,0); my $button1 = Gtk2::Button->new('VIEW'); $button1->signal_connect('clicked',\&view); $vbox->pack_start($button1,0,1,0); my $button2 = Gtk2::Button->new('IMPLODE'); $button2->signal_connect('clicked',\&implodeimage); $vbox->pack_start($button2,0,1,0); $window->show_all; Gtk2->main; sub load { $image = Image::Magick->new; $image2 = Image::Magick->new; $pimage = Image::Magick->new; $pimage2 = Image::Magick->new; $pimage->Read('frames/rbs5r.png'); $pimage2->Read('pictures/dscf6098.jpg'); $image = $pimage->Clone; $image2 = $pimage2->Clone; $image->Resize( height=>650, width=>(650*$image->Get('width')/$image->Get('height'))); $image2->Resize( height=>650, width=>(650*$image2->Get('width')/$image2->Get('height'))); $canvas = Image::Magick->new; my $w = $image->Get('width'); my $h = $image->Get('height'); my $size = $w . "x" . $h; $canvas->Set(size=>$size); $canvas->ReadImage('xc:white'); $canvas->Set(magick=>'jpeg'); $canvas->Composite( image=>$image2, compose=>'Over'); $canvas->Composite( image=>$image, compose=>'Over'); my $blob = $canvas->ImageToBlob(); $pixbufloader = Gtk2::Gdk::PixbufLoader->new; $pixbufloader->write($blob); $pixbufloader->close; $pixbuf = $pixbufloader->get_pixbuf; $blob = $pixbuf->save_to_buffer('jpeg'); $canvas->BlobToImage($blob); $canvas->Display; #my $preview = $image->Preview('Gamma'); #$preview->Display(); } sub view { #$pixbuf = Gtk2::Gdk::Pixbuf->new_from_file('text.bmp'); $image1->set_from_pixbuf($pixbuf); } sub implodeimage { print "IMPLODE\n"; # print $image2->Blur(20); #$canvas=$image->Clone; $canvas = Image::Magick->new; my $w = $image->Get('width'); my $h = $image->Get('height'); my $size = $w . "x" . $h; $canvas->Set(size=>$size); $canvas->ReadImage('xc:white'); #$image->Crop(geometry=>$size); #$image2->Crop(geometry=>$size); #$image2->Rotate(45); print $canvas->Composite(image=>$image2,compose=>'Over'); print $canvas->Composite(image=>$image,compose=>'Over'); print $canvas->Write('text.bmp'); }
you can try this out. first change the image files inside the SUB LOAD. run the program and press the LOAD BUTTON. the sub LOAD does the following... open a file using image magick. do something to it then convert it to a blob. then the blob is read by the pixbufloader and is then converted into a pixbuf! yey! then the pixbuf is then converted to a blob. which is then read by image magick!!!! yey!!!!

Replies are listed 'Best First'.
Re^3: PerlMagick Gtk2::Gdk::Pixbuf
by zentara (Archbishop) on Jul 22, 2008 at 12:01 UTC
    A couple of comments. First your use of the word canvas for a ImageMagick object is slightly confusing, but it's legal. Second, I know it's just a preliminary example, but if you are going to make it into an app that will load many pictures and operate on them, you should make your IM objects global and reuse them, so you are not making new ones all the time. You can clear out an IM object with
    #reuse object undef @$IMagick_object; # clear out IM object data

    I'm not really a human, but I play one on earth Remember How Lucky You Are

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://699193]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-05-19 02:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (71 votes). Check out past polls.

    Notices?