include Magick class PictureEditController < ApplicationController # To load an image into the PictureEditController, write a method # that does the following: # * Destroy any current image by calling @photo.destroy # * "Sanitize" the filename of the new image if required by calling # sanitize_filename() # * Re-initialize the session by calling init_session(new_image_filename) # * Create a new Photo object: @photo = Photo.new(session) # * Try to load the file: @photo.load(new_image_filename) # PictureEditController stores data for a single image in the session # These filters take care of loading and saving it before_filter :load_photo after_filter :save_photo def show end # You should not have to override these methods. They are called from # the control panel (see _control_panel.rhtml) def rotate_right @photo.rotate(90) unless @photo.nil? show_photo end def rotate_left @photo.rotate(-90) unless @photo.nil? show_photo end def brighter @photo.brighter(true) unless @photo.nil? show_photo end def darker @photo.brighter(false) unless @photo.nil? show_photo end def increase_contrast @photo.adjust_contrast(true) unless @photo.nil? show_photo end def reduce_contrast @photo.adjust_contrast(false) unless @photo.nil? show_photo end def crop unless @photo.nil? if params['crop_button'] == "Preview" @photo.preview_crop(params['left'], params['top'], params['right'], params['bottom']) else @photo.crop(params['left'], params['top'], params['right'], params['bottom']) end end show_photo end def set_max_size @photo.set_max_size(params['horiz'], params['vert']) unless @photo.nil? show_photo end def more_red @photo.adjust_red(true) unless @photo.nil? show_photo end def more_cyan @photo.adjust_red(false) unless @photo.nil? show_photo end def more_green @photo.adjust_green(true) unless @photo.nil? show_photo end def more_magenta @photo.adjust_green(false) unless @photo.nil? show_photo end def more_blue @photo.adjust_blue(true) unless @photo.nil? show_photo end def more_yellow @photo.adjust_blue(false) unless @photo.nil? show_photo end def enhance_color_contrast @photo.enhance_color_contrast unless @photo.nil? show_photo end def sharpen @photo.sharpen unless @photo.nil? show_photo end def reduce_noise @photo.reduce_noise unless @photo.nil? show_photo end def undo @photo.undo unless @photo.nil? show_photo end def start_over @photo.revert unless @photo.nil? show_photo end def finalize @photo.refresh_working_copy unless @photo.nil? show_photo end private def sanitize_filename(filename) filename = File.basename(filename.gsub("\\", "/")) # work-around for IE filename.gsub!(/[^a-zA-Z0-9\.\-\+_]/,"_") filename = "_#{filename}" if filename =~ /^\.+$/ filename = "unnamed" if filename.size == 0 filename end def init_session(photo_file_name) @session[:photo_params] = nil @session[:f_name] = photo_file_name end def load_photo if !@session[:f_name].blank? @photo = Photo.new(@session) else @photo = nil end end def save_photo @photo.save(@session) unless @photo.nil? end def show_photo render :partial => 'photo' end end