Module: Drakkon::Images::Blur
- Defined in:
- lib/drakkon/lib/images/blur.rb
Overview
General Image Index Helper
Class Method Summary collapse
- .images ⇒ Object
- .process(file, filter, size) ⇒ Object
- .prompt ⇒ Object
- .run!(args = []) ⇒ Object
- .start(filter, size) ⇒ Object
Class Method Details
.images ⇒ Object
65 66 67 |
# File 'lib/drakkon/lib/images/blur.rb', line 65 def self.images Dir["#{Dir.pwd}/**/*.png"] end |
.process(file, filter, size) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/drakkon/lib/images/blur.rb', line 53 def self.process(file, filter, size) image = MiniMagick::Image.open(file) # Ignore if the same return if image.width == size.split('x', 2).first.to_i LogBot.info('Image Blur', "Blurring: #{file}") image.filter filter image.blur size image.write file end |
.prompt ⇒ Object
69 70 71 |
# File 'lib/drakkon/lib/images/blur.rb', line 69 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 36 37 38 39 40 41 42 43 44 |
# File 'lib/drakkon/lib/images/blur.rb', line 5 def self.run!(args = []) # Sizing size = if args.empty? prompt.ask('Blur Size? (e.g. 20x20): ', default: '5x5') else args.shift end # TODO: Recommend as Options # TODO: Blur Options # Potentially Support Custom Filters? filter = if args.empty? 'Gaussian' else args.shift end puts <<~HELP Usage [size] [filter = Gaussian] - Run in the directory you wish to modify the images - Blurs the images via MiniMagick Filter: #{filter} to Size: #{size} 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 exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Blur!? #{'(Destructive)'.pastel(:red)}" start(filter, size) end |