Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get screen resolution in ruby

How to get screen resolution (height, width) in ruby script?

like image 830
dyak Avatar asked Aug 12 '26 08:08

dyak


2 Answers

On Linux:

x, y = `xrandr`.scan(/current (\d+) x (\d+)/).flatten

On windows, use WIN32OLE and such.

like image 172
steenslag Avatar answered Aug 15 '26 08:08

steenslag


This is how I solved my problem of getting resolution. As I was using Ruby 2.3.0, I cannot use DL module(as its been depricated). Following is by using Fiddle

usr32=Fiddle::dlopen("user32")
gsm=Fiddle::Function.new(usr32["GetSystemMetrics"],[Fiddle::TYPE_LONG],Fiddle::TYPE_LONG)
x= gsm.call(0)
y= gsm.call(1)
puts x,y
like image 24
Murali Krishna Avatar answered Aug 15 '26 10:08

Murali Krishna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!