Sha256: b6831b282c74dde5926a828ffc2b1594f92ef54a03a302240f62e9f7426ff8fc

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

#
# Strategy for build a scaled image
#
class ScaledImageStrategy

  attr_reader :name, :width, :height, :quality

  def initialize( name, width, height, quality )
    @name = name
    @width = width
    @height = height
    @quality = quality
  end


  #
  # build a scaled image and store it in outpath
  #
  # inpath source image file
  # outpath destination image file
  #
  # TODO: sostituire inpath con PhotoFile
  # TODO: sostituire outpath con ImageFile
  def build( inpath, outpath )
    # TODO: ritornare un risultato per es. 1 = skipped 2 = copiato 3 = scalata immagine
    result_msg = ""
    img = Magick::ImageList.new(inpath)

    if @width > img.columns and @height > img.rows
      result_msg = "(c) "
      # FileUtils.cp( inpath, outpath )
      # rimuovere i metadata
    else
      result_msg = "(#{@quality}%) "
      img.resize_to_fit!(@width, @height)
    end
    img.profile!('*', nil)

    img.write(outpath) {|i| i.quality = quality }
    result_msg
  end

  def write_xml( xml_iss )
    xml_is = xml_iss.add_element( "image_strategy")
    xml_is.attributes["name"] = self.class.to_s
    xml_par = xml_is.add_element("par")
    xml_par.attributes["width"] = @width.to_s
    xml_par.attributes["height"] = @height.to_s
    xml_par.attributes["quality"] = @quality.to_s
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gf-ralbum-0.0.5 lib/ralbum/image_strategies/scaled_image_strategy.rb