lib/yamg/icon.rb in yamg-0.5.3 vs lib/yamg/icon.rb in yamg-0.5.5

- old
+ new

@@ -15,22 +15,22 @@ # Export image # # ICO: 16/32/48 # def initialize(src, size, bg = nil, rounded = false, radius = 9) - fail 'No source' if src.nil? || src.empty? + raise 'No source' if src.nil? || src.empty? @src = src - @size = size + @size = size @rounded = rounded @icons = YAMG.load_images(src) YAMG.puts_and_exit("No sources in '#{src}'") if icons.empty? @choosen = File.join(src, find_closest_gte_icon) @radius = radius || 9 # @dpi = 90 @bg = bg end - alias_method :rounded?, :rounded + alias rounded? rounded def find_closest_gte_icon proc = ->(x) { x.tr('^0-9', '').to_i } return icons.max_by(&proc) if icons.map(&proc).max < size icons.min_by do |f| @@ -49,17 +49,16 @@ # # Maybe this can be smaller, terminal equivalent: # convert # -size 512x512 xc:none - # -draw "roundrectangle 0,0,512,512,55,55" mask.png - # convert icon.png + # -draw "roundrectangle 0,0,512,512,55,55" mask.png convert icon.png # -matte mask.png # -compose DstIn # -composite picture_with_rounded_corners.png # https://gist.github.com/artemave/c20e7450af866f5e7735 - def round(r = 14) + def round mask = MiniMagick::Image.open(img.path) mask.format 'png' mask.combine_options do |m| m.alpha 'transparent' @@ -96,11 +95,11 @@ clone.composite(img) { |i| i.compose 'Over' } end # Just copy the svg, never resize def svg! - fail unless @icons.find { |i| File.extname(i) == 'svg' } + raise unless @icons.find { |i| File.extname(i) == 'svg' } end # ICO! def ico!(out) temp = ->(s) { "/tmp/#{s}-#{Thread.current.object_id}.png" } @@ -121,10 +120,9 @@ pixels = dpi ? "-d #{dpi} -p #{dpi}" : nil args = "#{pixels} -w #{size} -h #{size} -f png" YAMG.run_rsvg(@choosen, temp, args) @img = MiniMagick::Image.open(temp) @img.format File.extname(out) if out - else @img = MiniMagick::Image.open(@choosen) @img.format File.extname(out) if out @img.resize size # "NxN" end