0
@@ -38,6 +38,9 @@ module Fleximage
0
# very large in filesize.
0
# * +default_image_path+: (String, nil default) If no image is present for this record, the image at this path will be
0
# used instead. Useful for a placeholder graphic for new content that may not have an image just yet.
0
+ # * +default_image+: A hash which defines an empty starting image. This hash look like: <tt>:size => '123x456',
0
+ # :color => :transparent</tt>, where <tt>:size</tt> defines the dimensions of the default image, and <tt>:color</tt>
0
+ # defines the fill. <tt>:color</tt> can be a named color as a string ('red'), :transparent, or a Magick::Pixel object.
0
# * +preprocess_image+: (Block, no default) Call this class method just like you would call +operate+ in a view.
0
# The image transoformation in the provided block will be run on every uploaded image before its saved as the
0
@@ -51,8 +54,9 @@ module Fleximage
0
# image_storage_format :png
0
# missing_image_message 'is required'
0
- # invalid_image_message 'was not a readable image'
0
+ # invalid_image_message 'was not a readable image'
\0
# default_image_path 'public/images/no_photo_yet.png'
0
# output_image_jpg_quality 85
0
# preprocess_image do |image|
0
@@ -118,6 +122,9 @@ module Fleximage
0
# Set a default image to use when no image has been assigned to this record
0
dsl_accessor :default_image_path
0
+ # Set a default image based on a a size and fill
0
+ dsl_accessor :default_image
0
# A block that processes an image before it gets saved as the master image of a record.
0
# Can be helpful to resize potentially huge images to something more manageable. Set via
0
# the "preprocess_image { |image| ... }" class method.
0
@@ -444,10 +451,19 @@ module Fleximage
0
# Load the default image, or raise an expection
0
def master_image_not_found
0
- # Load the default image
0
+ # Load the default image
from a path0
if self.class.default_image_path
0
@output_image = Magick::Image.read("#{RAILS_ROOT}/#{self.class.default_image_path}").first
0
+ # Or create a default image
0
+ elsif self.class.default_image
0
+ x, y = Fleximage::Operator::Base.size_to_xy(self.class.default_image[:size])
0
+ color = self.class.default_image[:color]
0
+ @output_image = Magick::Image.new(x, y) do
0
+ self.background_color = color if color && color != :transparent
0
# No default, not master image, so raise exception
0
message = "Master image was not found for this record"