Last active
November 23, 2018 16:03
-
-
Save denoww/4f7c739661d25b6c34359a2f2d1fabc0 to your computer and use it in GitHub Desktop.
svg_to_app_icons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vars | |
folder = '/home/rodrigo/Downloads/icones-erp' | |
WIDTH = 192 | |
COLORS = { | |
'blue' => '#3B729D', | |
'white' => '#FFFFFF', | |
'black' => '#000000' | |
} | |
# Implementation | |
require 'fileutils' | |
def generate_images folder | |
COLORS.each do |color_name, hex_color| | |
folder_color = "#{folder}/icones/#{color_name}" | |
FileUtils::mkdir_p folder_color | |
Dir.glob("#{folder}/*.svg").sort.each do |svg| | |
change_svg_color(svg, hex_color) | |
file_name = svg.split('/')[-1] | |
name, extension = file_name.split('.') | |
name = "sc_icon_#{name.gsub('-', '_')}_#{color_name}" | |
# name = "sc_icon_#{name.gsub('-', '_')}" | |
output = `inkscape -w=#{WIDTH} -z #{svg} -e #{folder_color}/#{name}.png` | |
puts "#{output}\n" | |
end | |
end | |
end | |
def change_svg_color svg, color | |
icomoon_color = ['#444'] | |
possible_latest = COLORS.values + icomoon_color | |
possible_latest.each do |last_color| | |
`sed -i '/#{last_color}/s/#{last_color}/#{color}/g' #{svg}` | |
end | |
end | |
generate_images folder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment