some file exceptions sorted
This commit is contained in:
parent
68e301a00b
commit
8ad705eec5
24
file_nav.rb
24
file_nav.rb
|
@ -4,10 +4,10 @@ class DirTermine
|
||||||
|
|
||||||
attr_accessor :save_dir, :source_dir
|
attr_accessor :save_dir, :source_dir
|
||||||
|
|
||||||
def initialize
|
# def initialize
|
||||||
@save_dir = save_dir
|
# @save_dir = save_dir
|
||||||
@source_dir = source_dir
|
# @source_dir = source_dir
|
||||||
end
|
# end
|
||||||
|
|
||||||
def destination_dir
|
def destination_dir
|
||||||
puts 'Please enter desired save directory (Leave blank for ~/Pictures/stickerized)'
|
puts 'Please enter desired save directory (Leave blank for ~/Pictures/stickerized)'
|
||||||
|
@ -20,11 +20,11 @@ class DirTermine
|
||||||
dir = gets.chomp
|
dir = gets.chomp
|
||||||
Dir.getwd if dir.empty?
|
Dir.getwd if dir.empty?
|
||||||
end
|
end
|
||||||
|
#
|
||||||
def establish_dirs
|
# def establish_dirs
|
||||||
@source_dir = File.expand_path(origin_dir)
|
# @source_dir = File.expand_path(origin_dir)
|
||||||
@save_dir = File.expand_path(destination_dir)
|
# @save_dir = File.expand_path(destination_dir)
|
||||||
end
|
# end
|
||||||
|
|
||||||
def dbug
|
def dbug
|
||||||
puts @source_dir
|
puts @source_dir
|
||||||
|
@ -32,6 +32,6 @@ class DirTermine
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
testr = DirTermine.new
|
# testr = DirTermine.new
|
||||||
testr.establish_dirs
|
# testr.establish_dirs
|
||||||
testr.dbug
|
# testr.dbug
|
||||||
|
|
6
main.rb
Normal file
6
main.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative 'stickerizer'
|
||||||
|
|
||||||
|
sticker_machine = Stickerizer.new
|
||||||
|
sticker_machine.convert_images
|
|
@ -1,12 +1,44 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'mini_magick'
|
require 'mini_magick'
|
||||||
|
require_relative 'file_nav'
|
||||||
|
|
||||||
class Stickerizer
|
class Stickerizer
|
||||||
|
def initialize
|
||||||
|
@convert = DirTermine.new
|
||||||
|
end
|
||||||
|
|
||||||
def stickerize(pic_file, save_dir)
|
def stickerize(pic_file, save_dir)
|
||||||
image = MiniMagick::Image.open(pic_file)
|
image = MiniMagick::Image.open(pic_file)
|
||||||
image.resize '512x512'
|
image.resize '512x512'
|
||||||
image.format 'png'
|
image.format 'png'
|
||||||
image.write "#{save_dir}#{pic_file}"
|
image.write "#{save_dir}#{pic_file}_stickerized.png"
|
||||||
|
end
|
||||||
|
|
||||||
|
def origin_dir
|
||||||
|
@convert.origin_dir
|
||||||
|
end
|
||||||
|
|
||||||
|
def dest_dir
|
||||||
|
@convert.destination_dir
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid?(file)
|
||||||
|
valid = false
|
||||||
|
extension = file[-4..-1]
|
||||||
|
valid = true if extension == '.png'
|
||||||
|
valid = true if extension == '.jpg'
|
||||||
|
valid = true if extension == '.gif'
|
||||||
|
puts "File #{file}: valid: #{valid.to_s}"
|
||||||
|
valid
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert_images
|
||||||
|
origin = origin_dir
|
||||||
|
destination = dest_dir
|
||||||
|
Dir.children(origin).each do |unstickerized|
|
||||||
|
next unless valid?(unstickerized)
|
||||||
|
stickerize("#{origin}/#{unstickerized}", destination)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue