Created
November 1, 2023 11:03
-
-
Save kiinoda/f71e5a2a302c901a98b5a851877c0a22 to your computer and use it in GitHub Desktop.
round corners for your png pics
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
#!/usr/bin/env ruby | |
# I haven't tested this lately but it did work at some point in time. | |
require 'rubygems' | |
require 'RMagick' | |
include Magick | |
Dir.new(".").entries.each do |src_name| | |
if src_name.include?(".png") && ! src_name.include?("_r.png") | |
source = Image.read(src_name).first | |
#source.resize!(0.5) | |
mask = Image.new(source.columns, source.rows) {self.background_color = 'black'} | |
gc = Draw.new | |
gc.stroke('white').fill('white') | |
gc.roundrectangle(0, 0, source.columns-1, source.rows-1, 10, 10) | |
gc.draw(mask) | |
mask.matte = false | |
source.matte = true | |
destination = source.composite(mask, CenterGravity, CopyOpacityCompositeOp) | |
dst_name = src_name.gsub(/.png$/, "").gsub(/ /, "_") | |
destination.write("#{dst_name}_r.png") { self.quality = 100 } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment