-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-resolution.rb
executable file
·42 lines (35 loc) · 956 Bytes
/
get-resolution.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env ruby
require 'nokogiri'
if ARGV.length != 2
STDERR.puts "Need an input file and DPI"
exit 1
end
CAST_BASE=ARGV[0]
DPI=ARGV[1].to_i
DEFAULT_DPI=96
file = "#{CAST_BASE}/termtosvg_00000.svg"
doc = Nokogiri::XML(File.open(file))
svg = doc.xpath('/xmlns:svg/xmlns:svg')[0]
width = svg['width'].to_i
height = svg['height'].to_i
def will_work(width, height, dpi)
output_width = (width.to_f * (dpi/DEFAULT_DPI.to_f)).round
output_height = (height.to_f * (dpi/DEFAULT_DPI.to_f)).round
if ((output_width % 2)) > 0 or ((output_height % 2) > 0) or (output_width == 0) or (output_height ==0)
false
else
true
end
end
if not will_work(width, height, DPI)
lower=will_work(width, height, DPI - 1)
upper=will_work(width, height, DPI + 1)
puts "#{DPI} dpi won't work for video output."
if lower == true
puts "#{DPI - 1} dpi will work."
end
if upper == true
puts "#{DPI + 1} dpi will work."
end
exit 1
end