Sha256: 9c623bbbf499addf6dd9a97dfdadae5594a7776063de349d3240fb6e7dc77c90

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

require 'fileutils'
require 'RMagick'

module Burp
  module Util
  
    def self.commit(message = "auto commit")
      raise "missing git repo in burp cms directory" if `cd #{Burp.content_directory}; git st 2>&1`.match(/Not a git repository/)
      `cd #{Burp.content_directory}; git add .; git commit -a -m "Burp: #{message}"`
    end
    
    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 # We only downscale
          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
    
    
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
burp_cms-1.3.3 app/lib/burp/util.rb
burp_cms-1.3.2 app/lib/burp/util.rb