Module: Drakkon::Images::Double
- Defined in:
- lib/drakkon/lib/images/double.rb
Overview
General Image Index Helper
Class Method Summary collapse
- .double(file, alpha) ⇒ Object
- .images ⇒ Object
- .prompt ⇒ Object
- .run!(args = []) ⇒ Object
- .start(alpha) ⇒ Object
Class Method Details
.double(file, alpha) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/drakkon/lib/images/double.rb', line 43 def self.double(file, alpha) image = MiniMagick::Image.open(file) LogBot.info('Image Double', "#{File.basename file}") # Create a copy of the image for overlay = image.clone # Apply alpha to the overlay = .compose('Over') do |c| c.gravity 'center' # Center the overlay c.define "compose:args=1,0,0,#{alpha}" # Control the alpha end # Combine the original image and the overlay result = image.composite() do |c| c.gravity 'center' # Center the overlay on the original image end # Save the result result.write(file) end |
.images ⇒ Object
66 67 68 |
# File 'lib/drakkon/lib/images/double.rb', line 66 def self.images Dir["#{Dir.pwd}/**/*.png"] end |
.prompt ⇒ Object
70 71 72 |
# File 'lib/drakkon/lib/images/double.rb', line 70 def self.prompt TTY::Prompt.new(active_color: :cyan, interrupt: :exit) end |
.run!(args = []) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/drakkon/lib/images/double.rb', line 5 def self.run!(args = []) # Alpha alpha = if args.empty? prompt.ask('Amount of Doubled Alpha? (e.g. 0..1): ') else args.shift end LogBot.info('Double Image Alhpa', "Alpha: #{alpha}") puts <<~HELP Usage [alpha] - Run in the directory you wish to modify the images - Adds the layer onto itself with a alpha value via MiniMagick Current Directory; #{Dir.pwd.pastel(:yellow)} Images: HELP images.sort.each do |img| img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow) puts " - #{img_s}" end puts unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Double Images!? #{'(Destructive)'.pastel(:red)}" exit end start(alpha) end |
.start(alpha) ⇒ Object
37 38 39 40 41 |
# File 'lib/drakkon/lib/images/double.rb', line 37 def self.start(alpha) images.each do |img| double(img, alpha) end end |