Created
February 15, 2017 17:39
-
-
Save c80609a/b269ec78ddc650b1079f2dc232dd1f15 to your computer and use it in GitHub Desktop.
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
require 'mini_magick' | |
class Walker | |
def initialize | |
@filenames = [] | |
end | |
def walk(dirname) | |
# puts "directory: #{dirname}" | |
Dir.foreach(dirname) do |filename| | |
full_filename = File.join(dirname, filename) | |
if File.directory? full_filename | |
if filename != '.' && filename != '..' | |
walk(full_filename) | |
end | |
else | |
@filenames << full_filename | |
puts "file: #{full_filename}" | |
end | |
end | |
end | |
def filenames | |
@filenames | |
end | |
end | |
class Watermaker | |
def initialize(watermark_path) | |
@watermark_image = MiniMagick::Image.open(watermark_path) | |
end | |
def place_watermark(file_names) | |
puts "<Watermark.place_watermark> file_names.count = #{file_names.count}" | |
file_names.each do |original_path| | |
original_image = MiniMagick::Image.open(original_path) | |
result = original_image.composite(@watermark_image) do |c| | |
c.gravity 'Center' | |
end | |
puts "<Watermark.place_watermark> write #{original_path}." | |
result.write original_path | |
end | |
end | |
end | |
walker = Walker.new | |
walker.walk('/home/scout/git/untitled/work/masterkottage/flow/20170215_watermark/all_together/files/uploads') | |
watermarker = Watermaker.new 'files/watermark.png' | |
watermarker.place_watermark walker.filenames |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment