Skip to content

Commit b69361d

Browse files
committed
Make rsvg optional
1 parent da744f2 commit b69361d

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

lib/badge/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Badge
22

3-
VERSION = "0.8.3"
3+
VERSION = "0.8.4"
44
DESCRIPTION = "Add a badge overlay to your app icon"
55

66
def self.root

lib/badge/runner.rb

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
module 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

Comments
 (0)