Directories work when not specified
This commit is contained in:
parent
8ad705eec5
commit
3c31410afe
40
file_nav.rb
40
file_nav.rb
|
@ -4,34 +4,34 @@ class DirTermine
|
|||
|
||||
attr_accessor :save_dir, :source_dir
|
||||
|
||||
# def initialize
|
||||
# @save_dir = save_dir
|
||||
# @source_dir = source_dir
|
||||
# end
|
||||
def initialize
|
||||
@save_dir = save_dir
|
||||
@source_dir = source_dir
|
||||
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
|
||||
puts 'Please enter desired save directory (Leave blank for ~/Pictures/stickerized)'
|
||||
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
|
||||
|
||||
def origin_dir
|
||||
puts 'Please enter directory containing pictures to stickerize (Leave blank for current directory)'
|
||||
dir = gets.chomp
|
||||
Dir.getwd if dir.empty?
|
||||
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
|
||||
dir = Dir.getwd if dir.empty?
|
||||
puts File.expand_path(dir) + " IS ORIGIN"
|
||||
File.expand_path(dir)
|
||||
end
|
||||
|
||||
# testr = DirTermine.new
|
||||
# testr.establish_dirs
|
||||
# testr.dbug
|
||||
end
|
||||
|
|
|
@ -4,6 +4,13 @@ require 'mini_magick'
|
|||
require_relative 'file_nav'
|
||||
|
||||
class Stickerizer
|
||||
|
||||
Extension = Struct.new(:extension)
|
||||
|
||||
def file_ext(filename)
|
||||
Extension.new(filename[-4..-1])
|
||||
end
|
||||
|
||||
def initialize
|
||||
@convert = DirTermine.new
|
||||
end
|
||||
|
@ -11,8 +18,13 @@ class Stickerizer
|
|||
def stickerize(pic_file, save_dir)
|
||||
image = MiniMagick::Image.open(pic_file)
|
||||
image.resize '512x512'
|
||||
image.format 'png'
|
||||
image.write "#{save_dir}#{pic_file}_stickerized.png"
|
||||
image.format 'PNG'
|
||||
image.write(save_dir + '/' + stickername(pic_file))
|
||||
puts "#{pic_file} | #{save_dir}"
|
||||
end
|
||||
|
||||
def stickername(filename)
|
||||
"#{filename[0..-5]}_sticker.png"
|
||||
end
|
||||
|
||||
def origin_dir
|
||||
|
@ -25,11 +37,11 @@ class Stickerizer
|
|||
|
||||
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}"
|
||||
file_info = file_ext(file)
|
||||
valid = true if file_info.extension == '.png'
|
||||
valid = true if file_info.extension == '.jpg'
|
||||
valid = true if file_info.extension == '.gif'
|
||||
puts "File #{file}: valid: #{valid}"
|
||||
valid
|
||||
end
|
||||
|
||||
|
@ -38,7 +50,7 @@ class Stickerizer
|
|||
destination = dest_dir
|
||||
Dir.children(origin).each do |unstickerized|
|
||||
next unless valid?(unstickerized)
|
||||
stickerize("#{origin}/#{unstickerized}", destination)
|
||||
stickerize(unstickerized, destination)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue