Removed extraneous files
This commit is contained in:
parent
2e9f25cfa1
commit
37c67a9651
35
file_nav.rb
35
file_nav.rb
|
@ -1,35 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
# TODO: add recursion support to directories
|
||||
class DirTermine
|
||||
|
||||
attr_accessor :save_dir, :source_dir
|
||||
|
||||
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
|
||||
dir = default_dir if dir.empty? || dir.nil?
|
||||
create_dir(dir)
|
||||
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 = Dir.getwd if dir.empty?
|
||||
File.expand_path(dir)
|
||||
end
|
||||
|
||||
end
|
7
main.rb
7
main.rb
|
@ -1,7 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'stickerizer'
|
||||
|
||||
sticker_machine = Stickerizer.new
|
||||
sticker_machine.convert_images
|
|
@ -1,67 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'mini_magick'
|
||||
require_relative 'file_nav'
|
||||
|
||||
class Stickerizer
|
||||
|
||||
Extension = Struct.new(:extension)
|
||||
|
||||
def file_ext(filename)
|
||||
Extension.new(filename[-4..-1])
|
||||
end
|
||||
|
||||
ImageFormat = Struct.new(:size, :format)
|
||||
|
||||
def telegram_format
|
||||
ImageFormat.new('512x512', 'PNG')
|
||||
end
|
||||
|
||||
def initialize
|
||||
@convert = DirTermine.new
|
||||
end
|
||||
|
||||
def stickerize(pic_file, save_dir)
|
||||
sticker_format = telegram_format
|
||||
image = MiniMagick::Image.open(pic_file)
|
||||
image.resize sticker_format.size
|
||||
image.format sticker_format.format
|
||||
image.write(save_dir + '/' + stickername(pic_file))
|
||||
|
||||
end
|
||||
|
||||
def stickername(filename)
|
||||
file_only = filename.sub %r{/.+/}, ''
|
||||
"#{file_only[0..-5]}_sticker.png"
|
||||
end
|
||||
|
||||
def origin_dir
|
||||
@convert.origin_dir
|
||||
end
|
||||
|
||||
def dest_dir
|
||||
@convert.destination_dir
|
||||
end
|
||||
|
||||
def valid?(file)
|
||||
# TODO: Change this to check file types instead of relying on filenames
|
||||
valid = false
|
||||
file_info = file_ext(file)
|
||||
valid = true if file_info.extension.downcase == '.png'
|
||||
valid = true if file_info.extension.downcase == '.jpg'
|
||||
valid = true if file_info.extension.downcase == '.gif'
|
||||
puts "File #{file}: valid: #{valid}"
|
||||
valid
|
||||
end
|
||||
|
||||
def convert_images
|
||||
origin = origin_dir
|
||||
destination = dest_dir
|
||||
puts "#{origin} is origin"
|
||||
Dir.children(origin).each do |unstickerized|
|
||||
next unless valid?(unstickerized)
|
||||
|
||||
stickerize("#{origin}/#{unstickerized}", destination)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue