some file exceptions sorted

This commit is contained in:
reimage 2019-06-13 16:42:41 -07:00
parent 68e301a00b
commit 8ad705eec5
3 changed files with 51 additions and 13 deletions

View file

@ -4,10 +4,10 @@ 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 destination_dir
puts 'Please enter desired save directory (Leave blank for ~/Pictures/stickerized)'
@ -20,11 +20,11 @@ class DirTermine
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 establish_dirs
# @source_dir = File.expand_path(origin_dir)
# @save_dir = File.expand_path(destination_dir)
# end
def dbug
puts @source_dir
@ -32,6 +32,6 @@ class DirTermine
end
end
testr = DirTermine.new
testr.establish_dirs
testr.dbug
# testr = DirTermine.new
# testr.establish_dirs
# testr.dbug

6
main.rb Normal file
View file

@ -0,0 +1,6 @@
# frozen_string_literal: true
require_relative 'stickerizer'
sticker_machine = Stickerizer.new
sticker_machine.convert_images

View file

@ -1,12 +1,44 @@
# frozen_string_literal: true
require 'mini_magick'
require_relative 'file_nav'
class Stickerizer
def initialize
@convert = DirTermine.new
end
def stickerize(pic_file, save_dir)
image = MiniMagick::Image.open(pic_file)
image.resize '512x512'
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