14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/lib/burp/util.rb', line 14
def self.create_smaller_images(file_path)
upload_directory_path = "#{Burp.content_directory}uploads/"
sizes = {:small => [200,300],:medium => [600,900], :large => [1000,1500]}
image = Magick::ImageList.new(file_path).first
image.auto_orient!
sizes.each_pair do |key,value|
FileUtils.mkdir_p("#{upload_directory_path}#{key.to_s}")
target_path = "#{upload_directory_path}#{key.to_s}/#{File.basename(file_path)}"
if value[0] < image.columns
image.resize_to_fit(value[0],value[1]).write(target_path) { self.quality = 75 }
else
File.unlink(target_path) if File.exist?(target_path)
File.symlink("../#{File.basename(file_path)}",target_path)
end
end
image.destroy!
end
|