From 37c67a9651f48f2d156bbc2cc3cc156c99c2662d Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 22 Jun 2019 20:20:21 -0700 Subject: [PATCH] Removed extraneous files --- file_nav.rb | 35 -------------------------- main.rb | 7 ------ stickerizer.rb | 67 -------------------------------------------------- 3 files changed, 109 deletions(-) delete mode 100644 file_nav.rb delete mode 100755 main.rb delete mode 100644 stickerizer.rb diff --git a/file_nav.rb b/file_nav.rb deleted file mode 100644 index 32def83..0000000 --- a/file_nav.rb +++ /dev/null @@ -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 diff --git a/main.rb b/main.rb deleted file mode 100755 index b71c2d7..0000000 --- a/main.rb +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -require_relative 'stickerizer' - -sticker_machine = Stickerizer.new -sticker_machine.convert_images diff --git a/stickerizer.rb b/stickerizer.rb deleted file mode 100644 index 870b3b5..0000000 --- a/stickerizer.rb +++ /dev/null @@ -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