Sha256: 4470d51375ee7ebde728b7aedb5e0c62813b7e6d74a242e9285f701de906e0a5

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8
module LightResizer
  class ImageLoader
    class ResizeImage

      STORE_RESIZE_DIR = 'light_resize' #todo move to config option

      attr_accessor :original_filename, :original_relative_dir, :resize_prefix
      attr_reader :root_dir

      def initialize(root_dir)
        @root_dir = root_dir
      end

      def resize_prefix_dir
        STORE_RESIZE_DIR
      end

      # Resized file name '150x150_image.png'
      def filename
        resize_prefix + '_' + original_filename
      end

      # Relative resize image path '/some_dir/resize/150x150_image.png'
      def relative_path
        File.join(original_relative_dir, STORE_RESIZE_DIR, filename)
      end

      # Absolute image path
      def full_path
        File.join(@root_dir, relative_path)
      end

      # Absolute resize path {root}/some_dir/resize
      def dir_path
        File.dirname full_path
      end

      # {Bool} returns true if resize dir exist?
      def dir_exist?
        Dir.exist? dir_path
      end

      # {Bool} returns true if resize image exist?
      def image_exist?
        File.exist? full_path
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
light_resizer-0.1.4 lib/light_resizer/image_loader/resize_image.rb
light_resizer-0.1.2 lib/light_resizer/image_loader/resize_image.rb
light_resizer-0.1.1 lib/light_resizer/image_loader/resize_image.rb