Skip to content

Instantly share code, notes, and snippets.

@kei-p
Last active October 26, 2016 07:05
Show Gist options
  • Save kei-p/d34360375f2afddeaba7347975c2a544 to your computer and use it in GitHub Desktop.
Save kei-p/d34360375f2afddeaba7347975c2a544 to your computer and use it in GitHub Desktop.
Convert utils
#! /usr/bin/ruby
# Usage: convert-padding-button 3 "~/image/logo.png"
`which convert`
unless $? == 0
puts "Please install imagemagick"
puts "\t$ brew install imagemagick"
exit 1
end
type, src = ARGV
scale = type.to_i
req_size = 44
size = `identify -ping -format '%w %h' #{src}`
src_w, src_h = size.split(" ").map(&:to_i)
dst_w = [src_w, req_size * scale].max
dst_h = [src_h, req_size * scale].max
`convert #{src} -background transparent -gravity center -scale #{src_w}x#{src_h} -extent #{dst_w}x#{dst_h} #{src}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment