Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am looking for a tool that lets me select any pixel on the screen and get its RGB color and absolute (x, y) location.

I have used tools on Windows that show a large magnified square with a crosshair letting me easily select the pixel I want and get its details.

Is there anything like this for ubuntu?

share|improve this question
    
just curious why you are looking for this particular combination together...that may help us think of an answer. why do you want to know the x,y coordinates and the color? –  snowguy Jul 23 '12 at 17:42
    
I am writing an automation tool that sends keyboard and mouse input in response to seeing certain things on the screen. Some parts depend on using x,y offsets of certain buttons etc inside a window, and I'd like an easy way to find these offsets exactly. –  Andrew Jul 24 '12 at 23:50
    
If this is for the web and you're Firefox then there is a extension called ColorZilla. colorzilla.com/firefox –  Anonymous Jul 25 '12 at 1:26
    
Andrew, looks like Ian B wrote a tool that does just what you want. Seems like he deserves the bounty. –  snowguy Jul 26 '12 at 3:45

5 Answers 5

up vote 3 down vote accepted
+50

The best fit is...a tiny Windows tool called ColorPix (via WINE)

After searching long and hard, it appears none of the available tools for Ubuntu/Linux fulfill both your criteria, i.e. magnification and coordinate display.

So we go for a tiny Windows tool that -- critically -- just works with a default WINE install, no configuration, installation, DLLs, etc. needed.

  • It features adjustable zoom, one-click copy in multiple formats and co-ordinate display:

    enter image description here

1. Install Wine

sudo apt-get install wine

(that's it!)

2. Download ColorPix

ColorPix can be officially downloaded as a tiny, portable 600KB exe here

I suggest downloading directly to your local binaries directory with:

sudo wget -O/usr/local/bin/ColorPix.exe http://www.colorschemer.com/ColorPix.exe

3. Create a launcher for ColorPix

  • Let's get an icon first:

    sudo wget -O/usr/share/icons/colorpix.png http://cdn.alternativeto.net/i/22e49edc-efa7-e011-979d-0025902c7e73_11865.png
    
  • Press Alt+F2 now and type gksudo gedit /usr/share/applications/colorpix.desktop, and paste the below and save the file:

    [Desktop Entry]
    Name=ColorPix
    GenericName=ColorPix
    Comment=ColorPicker via WINE
    Exec=wine /usr/local/bin/ColorPix.exe
    Terminal=false
    Icon=/usr/share/icons/colorpix.png
    Type=Application
    StartupNotify=true
    
  • From a terminal, run:

    sudo chmod +x /usr/share/applications/colorpix.desktop
    
  • In a few seconds, it will be available in the launcher as:

    enter image description here

4. Using ColorPix

Start it, and the very first time it may take a few seconds while WINE initializes.

The screenshot below shows it in action, with:

  • The coordinates on the top
  • Color values in different formats below (click to copy to clipboard)
  • Adjustable magnifier below
  • Press any key once you are on your desired pixel to lock values

    enter image description here

share|improve this answer
    
Exactly what I was after, thanks! –  Andrew Jul 29 '12 at 1:27

There is a tool called gpick.

Here you can see an image of the tool. With gpick you can select pixels, see the HTML code, add colors to the palette and generate colors.

gpick

share|improve this answer
    
Thanks this almost does what I want but doesn't seem to show the pixel coordinates. –  Andrew Jul 15 '12 at 12:14
    
Could you also mark this question as completed? –  slashcrack Jul 15 '12 at 12:19
    
No - as I still don't have the answer :) –  Andrew Jul 22 '12 at 4:01

This will get you what you want I believe. Admittedly it is a few steps but it looks worse than it is since I showed each little step.

Setup

Install ImageMagick & Shutter.

sudo apt-get install imagemagick shutter

How to get the x,y coordinates and color

A. Open Shutter and click the selection button

pic of clicking selection button

B. Note that as you move your mouse around it will show you the x,y coordinates you are looking for.

enter image description here

When you've got the right place go ahead and click with your mouse button and draw a square to capture an image. (It doesn't really matter how large your image is just so long as you start it (top left corner) on the pixel of interest.)

enter image description here

C. Close the image in shutter

enter image description here

D. Run the following command from the terminal. This will give you the color values of the top left pixel.

convert ~/Pictures/Selection_001.png -crop 1x1+1+1 txt:- | sed -n 's/.* \(#.*\)/\1/p' 

E. While in the command line go ahead and delete the image so that the next time shutter takes a picture it gives it the same name. (Otherwise you'll need to adjust the name in the previous step (D).

rm ~/Pictures/Selection_001.png
share|improve this answer

Paste this code into a text editor, make it executable and run. When you choose a color with eyedropper, the x and y coordinates will appear at the top. EDIT: Made code to add a zoom window. To have it grab pixels outside of the window click the button (not the eyedropper). Click the button again to stop grabbing the pointer. Haven't figured out how to draw a crosshair with cairo, but you can probably use as is. I left some cairo code in there in case someone can tell me why my rectangle doesn't draw...

#!/usr/bin/python
from gi.repository import Gtk,Gdk, GdkPixbuf
import cairo

class picker(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.connect('delete-event', Gtk.main_quit)
        self.connect('motion-notify-event', self.motion_cb)
        self.connect('button-press-event',self.button_press)
        box=Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)

        #Setup area for coordinates and zoom window
        coordbox=Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.xcoor=Gtk.Label("x: ")
        coordbox.pack_start(self.xcoor, True, False, 1)
        self.ycoor=Gtk.Label("y: ")
        coordbox.pack_start(self.ycoor, True, False, 1)
        self.zoomwin=Gtk.Image()
        #Trying to draw on Gtk.Image with cairo for crosshairs... Not working
        self.zoomwin.connect('draw', self.draw) 
        self.zoomwin.set_app_paintable(True)
        coordbox.pack_start(self.zoomwin,True,True,1)
        self.buttongo=Gtk.Button("Pick Color")
        self.buttongo.connect('clicked',self.gobutton_activate)
        coordbox.pack_start(self.buttongo,True,True,1)
        box.pack_start(coordbox, True, False, 5)

        #Put in color wheel for tweaking color
        self.cp=Gtk.ColorSelection()
        self.cp.connect('color-changed', self.on_color_changed)
        box.pack_start(self.cp, True, True, 5)
        self.add(box)
        self.show_all()

        #Set some initial parameters
        self.w,self.h=10,10 #Size of zoomed image in pixels
        self.count=0
        self.window=self.get_window()
        #set initial zoom image
        self.zoomwin.set_from_pixbuf(self.get_image().scale_simple(240,240,GdkPixbuf.InterpType.TILES))
        self.grabbing=False

    def on_color_changed(self,widget=None, data=None):
        #Print out x,y to widgets
        display=Gdk.Display.get_default()
        (screen,x,y,modifier)=display.get_pointer()
        self.xcoor.set_text("x: %i" %x)
        self.ycoor.set_text("y: %i" %y)


    def get_image(self,w=None,h=None):
        #Get a pixbuff image under pointer
        if w==None: w=self.w
        if h==None: h=self.h
        display=Gdk.Display.get_default()
        (screen,self.x,self.y,modifier)=display.get_pointer()
        window=Gdk.get_default_root_window()
        screenshot = Gdk.pixbuf_get_from_window(window,
            self.x-int(w/2), self.y-int(h/2), int(w), int(h))
        return screenshot

    def motion_cb(self, widget, data):
        #What to do while mouse pointer is moving
        #DONT capture every event! Causes too much backup
        if self.count==5:
            self.pixbuf=self.get_image().scale_simple(240,240,GdkPixbuf.InterpType.TILES)
            self.zoomwin.set_from_pixbuf(self.pixbuf)
            self.zoomwin.queue_draw()
            self.count=0
        self.count+=1

    def grab_start(self):
        #Grab control of pointer outside of window
        self.grabbing = True
        Gdk.pointer_grab(self.window, 
                        True, #allow passage of pointer events to children
                        Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK,
                        None,
                        None,# could put a custom cursor here
                        0L)

    def button_press(self,widget,data):
        #capture color under the pointer and set the color selection
        cenpx=self.get_image(1,1)
        color=tuple(map(ord, cenpx.get_pixels()[:3]))
        col=Gdk.RGBA(float(color[0])/256.,float(color[1])/256.,float(color[2])/256.)
        self.cp.set_current_rgba(col)

    def grab_stop(self):
        #Stop Grabbing the pointer
        Gdk.pointer_ungrab(0)
        self.grabbing=False     

    def gobutton_activate(self, widget, data=None):
        #Button control
        if self.grabbing==False:
            self.grab_start()
            widget.set_label("Stop Picking")
        else:
            self.grab_stop()
            widget.set_label("Pick Color")

    def draw(self, widget, cr):
        #this gets called, but nothing is drawn that I can see...
        cr.set_operator(cairo.OPERATOR_SOURCE)
        cr.set_source_rgba(1,1,1,1)
        w = self.w
        h = self.h
        cr.set_source_rgba(1,1,1,1)
        cr.set_line_width(10)
        cr.rectangle(w/2-1,h/2-1,w/2+1,h/2+1)
        cr.stroke()
        cr.set_operator(cairo.OPERATOR_OVER)


if __name__=="__main__":
    win=picker()
    Gtk.main()
share|improve this answer
1  
Nice answer. Much more straightforward. –  snowguy Jul 24 '12 at 20:30
    
Got it working - but I can't see the pixel I'm about to select until after I click it. I was hoping to be able to magnify the area around the cursor so I can make sure I get exactly the right pixel. –  Andrew Jul 28 '12 at 3:32
    
Try it now... Interesting project and I learned a lot. Hope someone might be able to help me figure out why I can't draw on the zoom window with cairo. –  Ian B. Jul 28 '12 at 20:42

Try imview , it does show co-ordinates.

enter image description here

You can download its Doc page and man page here.

share|improve this answer
    
I can't see how to select pixels from the screen with this. –  Andrew Jul 22 '12 at 12:40

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.