Take a screenshot of the window the user clicks on and name the file the same as the window title

Take a screenshot of the window the user clicks on and name the file the same as the window title

1
 sleep 4; xwd >foo.xwd; mv foo.xwd "$(dd skip=100 if=foo.xwd bs=1 count=256 2>/dev/null | egrep -ao '^[[:print:]]+' | tr / :).xwd"

In general, this is actually not better than the “scrot -d4” command I’m listing it as an alternative to, so please don’t vote it down for that. I’m adding this command because xwd (X window dumper) comes with X11, so it is already installed on your machine, whereas scrot probably is not. I’ve found xwd handy on boxen that I don’t want to (or am not allowed to) install packages on.

NOTE: The dd junk for renaming the file is completely optional. I just did that for fun and because it’s interesting that xwd embeds the window title in its metadata. I probably should have just parsed the output from file(1) instead of cutting it out with dd(1), but this was more fun and less error prone.

NOTE2: Many programs don’t know what to do with an xwd format image file. You can convert it to something normal using NetPBM‘s xwdtopnm(1) or ImageMagick‘s convert(1). For example, this would work: “xwd | convert fd:0 foo.jpg”. Of course, if you have ImageMagick already installed, you’d probably use import(1) instead of xwd.

NOTE3: Xwd files can be viewed using the X Window UnDumper: “xwud

NOTE4: The sleep is not strictly necessary, I put it in there so that one has time to raise the window above any others before clicking on it.

* View this command to comment, vote or add to favourites * View all commands by hackerb9

commandlinefu.com

by David Winterbottom (codeinthehole.com)

URL: http://feedproxy.google.com/~r/Command-line-fu/~3/RK7WEj8ydPg/take-a-screenshot-of-the-window-the-user-clicks-on-and-name-the-file-the-same-as-the-window-title

Enhanced by Zemanta

Repeat a portrait eight times so it can be cut out from a 6″x4″ photo and used for visa or passport photos

Repeat a portrait eight times so it can be cut out from a 6″x4″ photo and used for visa or passport photos

1
montage 2007-08-25-3685.jpg +clone -clone 0-1 -clone 0-3 -geometry 500 -frame 5 output.jpg

Yes, You could do it in the GIMP or even use Inkscape to auto-align the clones, but the command line is so much easier.

NOTE: The +clone and -clone options are just to shorten the command line instead of typing the same filename eight times. It might also speed up the montage by only processing the image once, but I’m not sure. “+clone” duplicates the previous image, the following two “-clone”s duplicate the first two and then the first four images.

NOTE2: The -frame option is just so that I have some lines to cut along.

BUG: I haven’t bothered to calculate the exact geometry (width and height) of each image since that was not critical for the visa photos I need. If it matters for you, it should be easy enough to set using the -geometry flag near the end of the command. For example, if you have your DPI set to 600, you could use “-geometry 800×1200!” to make each subimage 1? x 2 inches. You may want to use ImageMagick‘s “-density 600” option to put a flag in the JPEG file cuing the printer that it is a 600 DPI image.

BUG2: ImageMagick does not autorotate images based on the EXIF information. Since the portrait photo was taken with the camera sideways, I made the JPEG rotate using jhead like so: jhead -autorot 2007-08-25-3685.jpg

* View this command to comment, vote or add to favourites * View all commands by hackerb9

commandlinefu.com

by David Winterbottom (codeinthehole.com)

URL: http://feedproxy.google.com/~r/Command-line-fu/~3/RxOm5plaH2M/repeat-a-portrait-eight-times-so-it-can-be-cut-out-from-a-6×4-photo-and-used-for-visa-or-passport-photos

Enhanced by Zemanta