66module Badge
77 class Runner
88 @@retry_count = Badge . shield_io_retries
9+ @@rsvg_enabled = true
910
1011 def run ( path , options )
1112 check_tools!
@@ -91,21 +92,31 @@ def add_shield(icon, result, shield, alpha_channel, shield_gravity, shield_no_re
9192 UI . message "'#{ icon . path } '"
9293 UI . verbose "Adding shield.io image ontop of icon" . blue
9394
94- new_path = "#{ shield . path } .png"
9595 shield_scale = shield_scale ? shield_scale . to_f : 1.0
9696
97- if shield_no_resize
98- `rsvg-convert #{ shield . path } -z #{ shield_scale } -o #{ new_path } `
97+ if @@rsvg_enabled
98+ new_path = "#{ shield . path } .png"
99+ if shield_no_resize
100+ `rsvg-convert #{ shield . path } -z #{ shield_scale } -o #{ new_path } `
101+ else
102+ `rsvg-convert #{ shield . path } -w #{ ( icon . width * shield_scale ) . to_i } -a -o #{ new_path } `
103+ end
104+ new_shield = MiniMagick ::Image . open ( new_path )
99105 else
100- `rsvg-convert #{ shield . path } -w #{ ( icon . width * shield_scale ) . to_i } -a -o #{ new_path } `
106+ new_shield = MiniMagick ::Image . open ( shield . path )
107+ if icon . width > new_shield . width && !shield_no_resize
108+ new_shield . resize "#{ ( icon . width * shield_scale ) . to_i } x#{ icon . height } <"
109+ else
110+ new_shield . resize "#{ icon . width } x#{ icon . height } >"
111+ end
101112 end
102113
103- result = composite ( result , MiniMagick :: Image . open ( new_path ) , alpha_channel , shield_gravity || "north" , shield_geometry )
114+ result = composite ( result , new_shield , alpha_channel , shield_gravity || "north" , shield_geometry )
104115 end
105116
106117 def load_shield ( shield_string )
107- url = Badge . shield_base_url + Badge . shield_path + shield_string + ".svg"
108- file_name = shield_string + ".svg"
118+ url = Badge . shield_base_url + Badge . shield_path + shield_string + ( @@rsvg_enabled ? ".svg" : ".png" )
119+ file_name = shield_string + ( @@rsvg_enabled ? ".svg" : ".png" )
109120
110121 UI . verbose "Trying to load image from shield.io. Timeout: #{ Badge . shield_io_timeout } s" . blue
111122 UI . verbose "URL: #{ url } " . blue
@@ -117,11 +128,12 @@ def load_shield(shield_string)
117128
118129 def check_tools!
119130 if !`which rsvg-convert` . include? ( 'rsvg-convert' )
120- UI . error ( "You have to install RSVG to use `badge` ")
121- UI . error ( "" )
122- UI . error ( "Install it using (RSVG):" )
131+ UI . important ( "Install RSVG to get better results for shields ontop of your icon ")
132+ UI . important ( "" )
133+ UI . important ( "Install it using (RSVG):" )
123134 UI . command ( "brew install librsvg" )
124- UI . user_error! ( "Install RSVG and start your lane again!" )
135+ UI . important ( "" )
136+ @@rsvg_enabled = false
125137 end
126138 return if `which convert` . include? ( 'convert' )
127139 return if `which gm` . include? ( 'gm' )
0 commit comments