== Using PSItsnotEngine 0. !!Make sure you have RMagick installed and accessible!! Type "irb" on the command line, then: irb(main):001:0> require 'rmagick' => true If this works, you're good to go! 1. Create your application: rails your_app_name 2. Change to your new application's directory: cd your_app_name 3. Install the "engines" plugin: script/plugin install engines 4. Install the PSItsnotEngine: script/plugin install "http://svn.openprofile.net/plugins/p_sitsnot_engine" 5. You'll need to provide at least a method to load an image, so generate a PictureEditController: script/generate controller PictureEdit 6. Now you need to do a bit of editing: - In application.rb, add the line "include PSitsnotEngine" within the class declaration - In application_helper.rb, add the line "include PSitsnotEngine" within the module declaration - You can alter the default PSitsnotEngine parameters by adding "module PSitsnotEngine" at the bottom of environment.rb. You can change any or all of the following parameters: module PSitsnotEngine # Maximum horizontal/vertical size to which an image will be re-sized config :max_output_size, 640 # When an image is loaded, it will be reduced so that the maximum # dimension is :max_cache_size pixels config :max_cache_size, 1024 # Image type to use for cached image config :cache_file_type, 'png' # Directory under RAILS_ROOT to use for cached images config :cache_dir_name, 'pictures' end - In environment.rb -- BELOW the "module PSitsnotEngine" if you have added it -- add the line "Engines.start :p_sitsnot_engine". - Add a method to picture_edit_controller.rb to load an image. This method needs to do 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) Here is a sample method, which creates a Photo from an image uploaded over the web: def upload if (request.method == :post) if (params['photo_file'].content_type !~ /image*/) flash[:notice] = "Image files only, please!" elsif (params['photo_file'].length > (4 * 1024 * 1024)) flash[:notice] = "Maximum 4 megabytes, please!" else f_name = sanitize_filename(params['photo_file'].original_filename) @photo.destroy if @photo init_session(f_name) @photo = Photo.new(session) begin logger.info "Trying to load #{@params['photo_file'].local_path}" @photo.load(params['photo_file']) flash[:notice] = "#{f_name} successfully uploaded." logger.info "Successfully loaded #{f_name}" rescue Exception => e logger.info "Failed to load #{f_name}" logger.info e flash[:notice] = "Unable to upload #{f_name} as picture" end end end redirect_to :action => 'show' end 7. Add a default route to routes.rb: map.connect '', :controller => "picture_edit", :action => 'show' 8. Delete or rename public/index.html 9. Type script/server in your shell window, and point your browser to "http://localhost:3000" 10. Select a file, upload it, and edit away! 11. Change the view to suit your application, add methods to the controller as desired. You can access the default stylesheet within your own views by adding the line: <%= engine_stylesheet "p_sitsnot_engine" %> in the portion of the view. 12. A Photo object can be loaded from a pathname, an open file, a TempFile, or a CGI StringIO object. Just add an appropriate method in your PictureEditController, following the general procedure shown above in the upload method. == License Copyright (c) 2006 Al Evans The MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.