Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'ftools'
- require 'RMagick'
- module SlideshowUpload
- @@image_types = ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg']
- @@slideshows_path = File.join(RAILS_ROOT, 'slideshows')
- mattr_reader :image_types, :slideshows_path, :file_data
- mattr_accessor :slideshow_path
- def self.included(base)
- base.send :extend, ImageProcessor
- base.class_eval do
- after_save :write_file
- after_destroy :destroy_images
- end
- end
- def image_data=(file_data)
- return nil if file_data.nil? || file_data.size == 0
- @image_data = file_data
- end
- def file_is_image?
- @image_types.include?(@image_data.content_type)
- end
- def write_image
- if @image_data && file_is_image?
- @slideshow_path = File.join(@slideshows_path, "slideshow_#{id}", "#{id}_original.#{@file_data}.#{extension}")
- File.makedirs(@slideshow_path) unless File.exist?(@slideshow_path)
- File.open(@slideshow_path, 'w') { |f| f.write(@image_data.read) }
- end
- end
- def destroy_images
- FileUtils.rm_rf("#{@slideshows_path}/slideshow_#{id}")
- end
- def extension
- @file_data.original_filename.split('.').last
- end
- module ImageProcessor
- @@image_versions = {:thumb => 'c100x100', :default => '500x500'}
- mattr_reader :image_versions
- def process!
- @image_versions.each do |iv|
- end
- end
- def resize(version, height, width, constrain)
- end
- end
- end
Add Comment
Please, Sign In to add comment