Created
August 13, 2018 16:16
-
-
Save NaiyaShah-BTC/9a7e6a8391f02865bc37735e702ca176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SIZES_ARR = [[167, 200, 'S'], [325, 390, 'M'], [625, 750, 'L']] | |
SIZES = [%w[small S], %w[medium M], %w[large L], %w[extra_large EL]] | |
def crop_and_resize | |
key = self.img.path[1..-1] | |
S3.bucket('unikaihatsu-s3').object(key).get(response_target: Rails.public_path.join(self.img_file_name)) | |
original_file = Rails.public_path.join(self.img_file_name) | |
image = Magick::Image.read(Dir.glob(original_file).first) | |
cropped_img = image[0].crop(150, 0, 1500, 1800).write(Rails.public_path.join("EL_#{self.img_file_name}")) | |
File.delete(original_file) if File.exist? original_file | |
SIZES_ARR.each do |size_data| | |
resize_image(cropped_img, size_data.first, size_data.second, size_data.last) | |
end | |
SIZES.each do |size| | |
upload_and_delete_local_file(key, size.first, size.last) | |
end | |
rescue => e | |
logger.error(e.message) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment