palkia has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone
I'm looking for a way to "snap" the screen (printscreen) so it (for example) can be manipulated with "Imager",
but without relaying on non-core modules (conversion to exe limitations).
Your thoughts ?
Thx

Update: Resolved
I'm am no longer limited by the "non-core modules" limitation (see this explanation for more details),
and therefore can now solve this problem without relaying on new information.

Regardless of the way this was eventually solved, I'd like to thank everyone for their replays (most appreciated), I have/will learn something from each.
Special thanks to "marto" & "Anonymous Monk", for not giving up on me despite reaching a massive Re^11 depth.
Wouldn't have figured this out without the feedback from you two.
  • Comment on print-screen without non-core modules ?

Replies are listed 'Best First'.
Re: print-screen without non-core modules ?
by marto (Cardinal) on May 26, 2012 at 19:17 UTC

    With pp you can create executables with "non-core" modules included.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: print-screen without non-core modules ?
by zentara (Cardinal) on May 26, 2012 at 20:09 UTC
    You will need to get over your aversion to non-core modules.

    The utility "import" from ImageMagick ( installed on most machines ) can capture the root window to a "blob", which can be manipulated by Imager or ImageMagick.

    #!/usr/bin/perl use warnings; use strict; use Image::Magick; my $blob = `import -window root jpg:-`; #my $blob = `import -`; #postscript produced #print "$blob\n"; # now $blob is in memory and you can do what you # want with it. my $output = Image::Magick->new(magick=>'jpg'); $output->BlobToImage( $blob ); #$output->Resize(geometry=>'160x120'); $output->Write( $0.'.jpg'); # png works too # or use Imager use Imager; # Convert image my $img = Imager->new; $img->read(data=>$blob, type=>'jpeg') or die "Cannot read: ", $img->errstr; #See perldoc Imager::Transformations my $rot20 = $img->rotate(degrees=>20); $rot20->write(file=>"$0-rot20.jpg", type=>'jpeg') or die "Cannot write: ",$rot20->errstr;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      "ImageMagick ( installed on most machines )"

      Nitpick: I wouldn't say most machines.

      Hi
      where can I find this for ActiveState Perl (Win)?
        The ImageMagick binary, which contains the "import" utility, is at IM binary releases.

        I'm not sure where the Window's perl module for ImageMagick can be found nowadays. Just so you are clear, there is a ImageMagick set of C libs and utilities ( cited above), and there is a PerlMagick Perl module. They are different entities.


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh
Re: print-screen without non-core modules ?
by Corion (Patriarch) on May 27, 2012 at 07:26 UTC
Re: print-screen without non-core modules ?
by BrowserUk (Patriarch) on May 28, 2012 at 17:38 UTC

    See Windows screengrab with GD;


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re: print-screen without non-core modules ?
by zentara (Cardinal) on Jun 01, 2012 at 09:31 UTC
    Here is another good one using Gtk2
    #!/usr/bin/perl use warnings; use strict; use Gtk2 -init; my $s = Gtk2::Gdk::Screen->get_default; my $w = $s->get_root_window; my $p = Gtk2::Gdk::Pixbuf->get_from_drawable ( $w, undef, 0, 0, 0, 0, $s->get_width, $s->get_height); $p->save ($0.'.jpg', 'jpeg', quality => 10);

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh