rul3r v1.3
rul3r v1.3
I needed to measure something, but didn't find a ruler, so I wrote one.
All it does is generate and display 3 rulers: Pixels, Centimeters and Inches.
The real DPI is calculated from xrandr's output and all floating-point calculations are done using awk (20 decimal places), so should be pretty accurate.
A tiny irregularities in distribution of millimeters marks may be visible, especially at lower resolutions, but I guess there's no way to avoid this, since it's impossible to convert analog (mm) to digital/discrete (px) values 100% accurately - it's just an approximation...
Requirements: xrandr, awk, cut, grep, seq, gtkdialog, xmessage.
___________
Changelog:
Version 1.1
- fixed: reading the width of the screen (thanks to MochiMoppel)
Version 1.2
- a warning window in case if obtaining the physical size of the display has failed (thanks to Jasper & mister_electronico)
- physical size of the display can be also defined manually in $HOME/.rul3r
Version 1.3
- fix in calculations for screens that have width smaller than height (thanks to MochiMoppel)
Enjoy &
Greetings!
All it does is generate and display 3 rulers: Pixels, Centimeters and Inches.
The real DPI is calculated from xrandr's output and all floating-point calculations are done using awk (20 decimal places), so should be pretty accurate.
A tiny irregularities in distribution of millimeters marks may be visible, especially at lower resolutions, but I guess there's no way to avoid this, since it's impossible to convert analog (mm) to digital/discrete (px) values 100% accurately - it's just an approximation...
Requirements: xrandr, awk, cut, grep, seq, gtkdialog, xmessage.
___________
Changelog:
Version 1.1
- fixed: reading the width of the screen (thanks to MochiMoppel)
Version 1.2
- a warning window in case if obtaining the physical size of the display has failed (thanks to Jasper & mister_electronico)
- physical size of the display can be also defined manually in $HOME/.rul3r
Version 1.3
- fix in calculations for screens that have width smaller than height (thanks to MochiMoppel)
Enjoy &
Greetings!
- Attachments
-
- rul3r-1.3.pet
- (2.71 KiB) Downloaded 572 times
-
- Screenshot.png
- (29.19 KiB) Downloaded 930 times
Last edited by SFR on Sat 07 Mar 2015, 10:29, edited 3 times in total.
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Re: rul3r v1.0
Funny. 2 days ago I needed to measure something, but didn't find a ruler, so I made pencil marks on the edge of my monitorSFR wrote:I needed to measure something, but didn't find a ruler, so I wrote one.
What I needed was a ruler or a grid that indicates number of pixel from position 0x0. A simple 1200x1600 grid wallpaper would do the job, but I was too lazy to create one.
Your ruler looks nice, but doesn't yet work for me. I'm used to rulers that start at zero
Your calculation of screen width is not correct.
Replace
Code: Select all
SCREEN_WIDTH=`xrandr | grep -wo '[0-9].*\*' | cut -f1 -d 'x'`
Code: Select all
SCREEN_WIDTH=$(xwininfo -root|awk '$1=="Width:"{print $2}')
- Attachments
-
- ruler.png
- (4.81 KiB) Downloaded 812 times
PicPick runs well in Wine
Hi MochiMoppel,
I don't remember if you use Wine and doubtless you could make (and by now may already have made) your own superb pixel ruler.
You may know about PicPick and its functions which include a pixel ruler, but if not there is http://www.picpick.org/en/ and a couple of screen shots below.
I got my excellent free copy from http://portableapps.com/
My regards
PS I'm up late as I've been trying to recover from a hard drive wipe out that's a major disappointment rather than a catastrophe.
I don't remember if you use Wine and doubtless you could make (and by now may already have made) your own superb pixel ruler.
You may know about PicPick and its functions which include a pixel ruler, but if not there is http://www.picpick.org/en/ and a couple of screen shots below.
I got my excellent free copy from http://portableapps.com/
My regards
PS I'm up late as I've been trying to recover from a hard drive wipe out that's a major disappointment rather than a catastrophe.
- Attachments
-
- PicPick.png
- (36.66 KiB) Downloaded 760 times
-
- Pixel ruler.png
- (17 KiB) Downloaded 753 times
Opacity would be handy
Code: Select all
<window title="'${APPNAME}'" resizable="false" opacity="0.5" image-name="/usr/share/pixmaps/rul3r.png">
- Attachments
-
- rul3r.jpg
- (72.67 KiB) Downloaded 742 times
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]
@Mochi: Usually I use xwininfo, but in this case I needed xrandr anyways, to get real size of the physical screen, so didn't want to introduce another dependency (I think I'm becoming a coding purist with age ).
Anyway, could you please post your xrandr output? Perhaps it can be fixed.
Here's mine for comparison:
EDIT: will this one work for you?
Thanks.
___________
@Geoffrey: Hmm, not a bad idea, but requires an environment that supports real transparency (like XFCE, which I assume is in your case?).
On the other hand, I wrote this app to measure objects from the real world, not those on the desktop (since it would allow to measure only items that are parallel to the x-axis), although a concept for another app is crystallizing as we speak, so maybe later.
Thanks guys &
Greetings!
Anyway, could you please post your xrandr output? Perhaps it can be fixed.
Here's mine for comparison:
Code: Select all
# xrandr
Screen 0: minimum 320 x 200, current 1366 x 768, maximum 8192 x 8192
LVDS connected 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 193mm
1366x768 60.0*+
1280x720 59.9
1152x768 59.8
1024x768 59.9
800x600 59.9
848x480 59.7
720x480 59.7
640x480 59.4
VGA-0 disconnected (normal left inverted right x axis y axis)
HDMI-0 disconnected (normal left inverted right x axis y axis)
DisplayPort-0 disconnected (normal left inverted right x axis y axis)
#
# xrandr | grep -wo '[0-9]*mm x [0-9]*mm' | cut -f1 -d 'm'
344
#
# xrandr | grep -wo '[0-9].*\*' | cut -f1 -d 'x'
1366
#
Code: Select all
xrandr | grep -wo -m1 'current [0-9]*' | cut -f2 -d ' '
___________
@Geoffrey: Hmm, not a bad idea, but requires an environment that supports real transparency (like XFCE, which I assume is in your case?).
On the other hand, I wrote this app to measure objects from the real world, not those on the desktop (since it would allow to measure only items that are parallel to the x-axis), although a concept for another app is crystallizing as we speak, so maybe later.
Thanks guys &
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
You are already a purist. I like your code. Looks like a well crafted poem ...well, almost.SFR wrote:I think I'm becoming a coding purist with age ).
Below my xrandr output, together with your fixed ruler (yes, your new code works for me).I also tinkered with thisidea and rolled my own. Works pretty well, but requires ImageMagick.
- Attachments
-
- Screenshot.png
- (30.99 KiB) Downloaded 731 times
Thanks Mochi
Ok, thank you for confirmation, v1.1 with the fix uploaded.
@Geoffrey et all: measur3r-1.0 is the app to measure stuff on the desktop.
Greetings!
Ok, thank you for confirmation, v1.1 with the fix uploaded.
@Geoffrey et all: measur3r-1.0 is the app to measure stuff on the desktop.
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
Hi SFR and co-conspirators,
That's brilliant and the screen shot demonstrates that you are spot on (and so was Pythagorus).
I seem to have everything you list, except my "xmessage" seems to like "gxmessage" and, perhaps strangely, I only see pixel measurements and my output screen is a fraction too small.
My regards, thanks and congratulations.
That's brilliant and the screen shot demonstrates that you are spot on (and so was Pythagorus).
I seem to have everything you list, except my "xmessage" seems to like "gxmessage" and, perhaps strangely, I only see pixel measurements and my output screen is a fraction too small.
My regards, thanks and congratulations.
- Attachments
-
- Shot(1).png
- (16.62 KiB) Downloaded 633 times
Hi Jasper
This indicates a problem with obtaining real screen dimensions.
Could you please post the output of xrandr command?
xmessage usually is a link to gxmessage and they share most of options, but the latter looks much better.
It should automatically adjust the window size to its content, but I may add '-geometry' option in next version.
Btw, on a general note, both rul3r and measur3r won't be working in VirtualBox (and probably other VMs), because xrandr returns '0mm x 0mm' there...
Thanks for testing &
Greetings!
This indicates a problem with obtaining real screen dimensions.
Could you please post the output of xrandr command?
xmessage usually is a link to gxmessage and they share most of options, but the latter looks much better.
It should automatically adjust the window size to its content, but I may add '-geometry' option in next version.
Btw, on a general note, both rul3r and measur3r won't be working in VirtualBox (and probably other VMs), because xrandr returns '0mm x 0mm' there...
Thanks for testing &
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
Hi again,
Thank for your response. Here is the requested output:
My regards
Thank for your response. Here is the requested output:
Code: Select all
# xrandr
xrandr: Failed to get size of gamma for output default
Screen 0: minimum 640 x 480, current 1024 x 768, maximum 1024 x 768
default connected 1024x768+0+0 0mm x 0mm
1024x768 0.0*
800x600 0.0
640x480 0.0
#
And that's the problem. I don't know why doesn't it show the size in your case and I don't know any other (reliable) way to get the needed info, unfortunately.default connected 1024x768+0+0 0mm x 0mm
I'm afraid you're just out of luck with this one.
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
This is a screen shot reminder about 5* Puppy measurement apps from SFR:
(1) xonclock (style, place and easily resize to suit)
(2) LFF (large files finder) There is a later version
(3) xonview (shows disk reads and writes) Full screen for graphics
(4) measur3r (in yellow) - calculates horiz/vert/diagonal distance
(5) PicPick (ruler as shown) uses Wine. SFR has issued rul3r v 1.2 as above.
My/our thanks go out to, the fiendishly clever, SFR and his co-conspirators.
(1) xonclock (style, place and easily resize to suit)
(2) LFF (large files finder) There is a later version
(3) xonview (shows disk reads and writes) Full screen for graphics
(4) measur3r (in yellow) - calculates horiz/vert/diagonal distance
(5) PicPick (ruler as shown) uses Wine. SFR has issued rul3r v 1.2 as above.
My/our thanks go out to, the fiendishly clever, SFR and his co-conspirators.
- Attachments
-
- Shot.png
- (79.61 KiB) Downloaded 608 times
Thanks Jasper.
Btw, since version 1.1, measur3r won't start if it's unable to determine physical size of the display (and user won't provide this info), so I have uploaded also measur3r_lite, which supports only pixel units.
Greetings!
Btw, since version 1.1, measur3r won't start if it's unable to determine physical size of the display (and user won't provide this info), so I have uploaded also measur3r_lite, which supports only pixel units.
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Hi SFR,
I tried rul3r v1.2. and see 2 issues:
1) My screen is 1200px wide, but what I get is only 1040px. Not enough to measure large screen elements. Your screenshot shows 1200px, so I guess it's not a deliberate limitation.
2) The cm calculation is wrong. The 35cm on your ruler actually is only 26cm, measured with a "real" ruler. And since 26cm would be about 10 inches, inches are also not correct In other words: The ruler exaggerates. I hope you didn't use it to measure important parts
I tried rul3r v1.2. and see 2 issues:
1) My screen is 1200px wide, but what I get is only 1040px. Not enough to measure large screen elements. Your screenshot shows 1200px, so I guess it's not a deliberate limitation.
2) The cm calculation is wrong. The 35cm on your ruler actually is only 26cm, measured with a "real" ruler. And since 26cm would be about 10 inches, inches are also not correct In other words: The ruler exaggerates. I hope you didn't use it to measure important parts
- Attachments
-
- rulers.png
- (40.19 KiB) Downloaded 526 times
Actually it is. The ruler's width is:MochiMoppel wrote:1) My screen is 1200px wide, but what I get is only 1040px. Not enough to measure large screen elements. Your screenshot shows 1200px, so I guess it's not a deliberate limitation.
SCREEN_WIDTH - 100 (to leave some margins for a window) - 50 (gap for Px/Cm/In text on the left) - some space on the right - window decorations.
But like I said earlier, this ruler was intended for measuring objects from the outside of the monitor. measur3r is the app designed for the other purpose.
I think I see what's the problem in your case - whereas your display's resolution is 1200x1600, xrandr reports its physical size as 408mm x 306mm (your previous screenshot), but shouldn't it be 306mm x 408mm..?MochiMoppel wrote:2) The cm calculation is wrong. The 35cm on your ruler actually is only 26cm, measured with a "real" ruler. And since 26cm would be about 10 inches, inches are also not correct
So, I've added this condition:
[ $SCREEN_WIDTH -lt $SCREEN_HEIGHT ] && [ $MM_WIDTH -gt $MM_HEIGHT ] && MM_WIDTH=$MM_HEIGHT
which hopefully fix this. Please try.
Same done to measur3r, btw.
It's better to exaggerate than shorten, isn't it?MochiMoppel wrote:In other words: The ruler exaggerates. I hope you didn't use it to measure important parts
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Longer or shorter, at least you are quicker. I just finished my calculation and it now produces the desired results:
Look Ma', no cut !
DVI-0 connected 1200x1600+0+0 left (normal left inverted right x axis y axis) 408mm x 306mm
Code: Select all
SCREEN_WIDTH=$(xrandr | grep -oP '(?<=current )[0-9]*')
SCREEN_HIGHT=$(xrandr | grep -oP '[0-9]*(?=, maximum)')
MM_DIMENSION=($(xrandr | grep -oP '[0-9]*?(?=mm)'))
MM_WIDTH=${MM_DIMENSION[0]}
MM_HIGHT=${MM_DIMENSION[1]}
[ $SCREEN_HIGHT -gt $SCREEN_WIDTH ] && MM_WIDTH=$MM_HIGHT
Should be, but xrandr doesn't like math. Instead it indicates the current orientation:xrandr reports its physical size as 408mm x 306mm (your previous screenshot), but shouldn't it be 306mm x 408mm..?
DVI-0 connected 1200x1600+0+0 left (normal left inverted right x axis y axis) 408mm x 306mm
Yeah, nicely done, perl-regexp rulez!MochiMoppel wrote:Look Ma', no cut !Code: Select all
SCREEN_WIDTH=$(xrandr | grep -oP '(?<=current )[0-9]*') SCREEN_HIGHT=$(xrandr | grep -oP '[0-9]*(?=, maximum)') MM_DIMENSION=($(xrandr | grep -oP '[0-9]*?(?=mm)'))
Unfortunately, in Fatdog (my main system now) grep is compiled without it, so FD users would have to install another version from repo...
Anyway, I just figured how to do it with awk (which is not my strong suit, so came to it mainly by trial & error):
Code: Select all
# xrandr | awk 'match($0,"current ([0-9]+) x [0-9]+",a) {print a[1]}'
1366
# xrandr | awk 'match($0,"current [0-9]+ x ([0-9]+)",a) {print a[1]}'
768
#
# xrandr | awk 'match($0,"([0-9]+)mm x [0-9]+mm",a) {print a[1]}'
344
# xrandr | awk 'match($0,"[0-9]+mm x ([0-9]+)mm",a) {print a[1]}'
193
#
Thanks, didn't notice.MochiMoppel wrote: Instead it indicates the current orientation
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Not so nice: I discovered that xrandr is extremely slow. Takes 0.4s on my machine to load, so calling xrandr 3 times as in my example will take more than a full second. This is a noticeable time lag. Calling it only once, as you do in your script, and then feed the output to a variable is a better idea.
Considering that xwininfo is 100 times faster than xrandr I try to avoid xrandr whenever I can, but I'm now puzzled by the results I get from xwininfo. As you can see, both tools report correct pixel dimensions, but millimeter dimensions for width/height are not only mixed up, they are different. The ones reported by xwininfo seem to be wrong. Any idea how they are calculated?
Considering that xwininfo is 100 times faster than xrandr I try to avoid xrandr whenever I can, but I'm now puzzled by the results I get from xwininfo. As you can see, both tools report correct pixel dimensions, but millimeter dimensions for width/height are not only mixed up, they are different. The ones reported by xwininfo seem to be wrong. Any idea how they are calculated?
- Attachments
-
- millimetermystery.png
- (48.71 KiB) Downloaded 216 times
Yep, xwininfo was my first choice when I began to write rul3r, but noticed the same thing and after small research it turned out that there was a change in Xorg at some point:
Greetings!https://bugs.freedesktop.org/show_bug.cgi?id=23705#c6 wrote:The 'screen size' as reported in the core protocol now respects the DPI value given by the user or config file and ignores the actual monitor DPI of any connected monitor.
The real monitor size is reported through the RandR extension if you really need to know the physical size of the display.
This is intentional and follows the practice seen in many other desktop environments where the logical DPI of the screen is used as an application and font scaling factor.
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]