Directories work when not specified

This commit is contained in:
Sean 2019-06-15 20:21:12 -07:00
parent 8ad705eec5
commit 3c31410afe
2 changed files with 39 additions and 27 deletions

View file

@ -4,34 +4,34 @@ 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 default_dir
File.expand_path('~/Pictures/stickerized')
end
def create_dir(dir)
Dir.mkdir(File.expand_path(dir)) unless File.directory?(File.expand_path(dir))
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)'
dir = gets.chomp dir = gets.chomp
'~/Pictures/stickerized' if dir.empty? dir = default_dir unless File.directory?(File.expand_path(dir))
create_dir(dir)
puts File.expand_path(dir) + " IS DESTINATION"
return File.expand_path(dir)
end end
def origin_dir def origin_dir
puts 'Please enter directory containing pictures to stickerize (Leave blank for current directory)' puts 'Please enter directory containing pictures to stickerize (Leave blank for current directory)'
dir = gets.chomp dir = gets.chomp
Dir.getwd if dir.empty? dir = Dir.getwd if dir.empty?
puts File.expand_path(dir) + " IS ORIGIN"
File.expand_path(dir)
end end
#
# def establish_dirs
# @source_dir = File.expand_path(origin_dir)
# @save_dir = File.expand_path(destination_dir)
# end
def dbug
puts @source_dir
puts @save_dir
end
end end
# testr = DirTermine.new
# testr.establish_dirs
# testr.dbug

View file

@ -4,6 +4,13 @@ require 'mini_magick'
require_relative 'file_nav' require_relative 'file_nav'
class Stickerizer class Stickerizer
Extension = Struct.new(:extension)
def file_ext(filename)
Extension.new(filename[-4..-1])
end
def initialize def initialize
@convert = DirTermine.new @convert = DirTermine.new
end end
@ -11,8 +18,13 @@ class Stickerizer
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}_stickerized.png" image.write(save_dir + '/' + stickername(pic_file))
puts "#{pic_file} | #{save_dir}"
end
def stickername(filename)
"#{filename[0..-5]}_sticker.png"
end end
def origin_dir def origin_dir
@ -25,11 +37,11 @@ class Stickerizer
def valid?(file) def valid?(file)
valid = false valid = false
extension = file[-4..-1] file_info = file_ext(file)
valid = true if extension == '.png' valid = true if file_info.extension == '.png'
valid = true if extension == '.jpg' valid = true if file_info.extension == '.jpg'
valid = true if extension == '.gif' valid = true if file_info.extension == '.gif'
puts "File #{file}: valid: #{valid.to_s}" puts "File #{file}: valid: #{valid}"
valid valid
end end
@ -38,7 +50,7 @@ class Stickerizer
destination = dest_dir destination = dest_dir
Dir.children(origin).each do |unstickerized| Dir.children(origin).each do |unstickerized|
next unless valid?(unstickerized) next unless valid?(unstickerized)
stickerize("#{origin}/#{unstickerized}", destination) stickerize(unstickerized, destination)
end end
end end
end end