Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to capture a window as a png from within a bash script, using the window's ID. In this case, the window is the top panel.  Using gnome-screenshot the colours are true, as per this image... (this image is not the same size as the following image, so ignore the dark line at the bottom)

enter image description here

However when I capture the panel via import, or xwd + convert, I get the following image..

enter image description here

Why would I be getting this colour aberration?

import and convert both belong to the imagemagick package...

I haven't found anything else in the Ubuntu repository which can capture a window by its ID... so I'm stuck. (gnome-screenshot doesn't have the feature)... It would be nice to know what is going on here (eg, is is something to do with transparent images, which I know very little about)...but in any case, just a recommendation of a workaround capture utility may do the trick ... it must be able to capture a window by it's ID.   

Here is an example of how I make and view the image capture.

import -window "$(wmctrl -l |grep "Top Expanded Edge Panel" |awk '{print $1}')" screen.png  
display screen.png
share|improve this question
    
Weird. ldd /usr/bin/program-that-displays-that-window and xdpyinfo might give some hint. –  Gilles Jul 6 '11 at 21:20
    
I've just tried the process in a newly installed 10.04 VM, same as the Host (described above), and also tried it in a newly installed 11.04 VM... The same thing happens in all situations... I've tried different viewers, and even viewed one of the .pngs in a Vista VM (same Host) .. It only happens with partial icons; ie. icons which don't run to the very perimeter of their alotted space... It makes me think it is related the the transparent features of images ??? –  Peter.O Jul 6 '11 at 22:43
    
Another test on a dual-boot Ubuntu 10.04 (newly installed.. but the same machine) produced the same results... I seems(guessing) that it is either my Graphics Card, or imagemagick.. This is the command: import -window "$(wmctrl -l |grep "Top Expanded Edge Panel" |awk '{print $1}')" screen.png; display screen.png ... –  Peter.O Jul 6 '11 at 23:15

1 Answer 1

up vote 1 down vote accepted

For making screens from console there is also scrot. As it is not a tool from imagemagick package I think that there is a chance that colors will be ok.

There is one problem - scrot can only take sceenshot of full screen, so we will take screenshot of full screen and then cut out area of window that we need. Of course for cut it out we will not use imagemagick but tools from netpbm package.

#!/bin/bash
unset x y w h
eval $(xwininfo -id $(wmctrl -l |grep "Top Expanded Edge Panel" |awk '{print $1}') |
        sed -ne "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
             -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
             -e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
             -e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
scrot scrot.pnm
    < scrot.pnm pnmcut -left $x -top $y -width $w -height $h | pnmtopng > scrot_cropped.png
display scrot_cropped.png

Could you check if with scrot you could make screenshot with unchanged colours? If yes that script should do the work and take screen of window that you want....


Script inspired on answers of @fred: How do I find the window dimensions and position accurately? and @JRW: Oneliner for slicing an image?

share|improve this answer
    
It works; there is no aberration, so it seems that import (imagemagick) is doing something differently to scrot. By the way, scrot can capture directly to .pnm; that saves one step, and there was an extra xdotool command (I've modified your answer). For my particular requirements, I'm still after a utility which grabs a window, because I want the the entire image, even when the window is partially covered. import does this, so I'm certainally still looking for something else which can grab a window by its ID... I'll keep the question open for a while yet. (netpbm looks interesting) –  Peter.O Jul 8 '11 at 4:25
    
I just noticed that @JRW in his "Oneliner for slicing an image?" question, mentioned that imagemagick garbled his mostly transparent .png.... That sure sounds like my problem! ..thanks for link –  Peter.O Jul 8 '11 at 4:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.