Class: Kirigami::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/kirigami/image.rb

Overview

An Image file to be compressed and cut via Kirigami

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, max_size) ⇒ Image

Create a new Image

max_size - An ImageSize to specify the size and name of image.



22
23
24
25
# File 'lib/kirigami/image.rb', line 22

def initialize(path, max_size)
  @path          = path
  @max_size      = max_size
end

Instance Attribute Details

#max_sizeObject (readonly)

An ImageMagick Image Geometry for the target file size www.imagemagick.org/script/command-line-processing.php#geometry

Returns String



10
11
12
# File 'lib/kirigami/image.rb', line 10

def max_size
  @max_size
end

#pathObject (readonly)

The filepath of the image to be cut

Returns Pathname



17
18
19
# File 'lib/kirigami/image.rb', line 17

def path
  @path
end

Instance Method Details

#cut!Object

Cuts the File down to size! Creates a backup copy first, if required.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kirigami/image.rb', line 28

def cut!
  create_backup_copy
  MiniMagick::Tool::Mogrify.new do |mogrify|
    mogrify.resize(max_size)
    mogrify.strip
    if jpeg?
      mogrify.colorspace(Kirigami.config.jpeg_colorspace)
      mogrify.sampling_factor(Kirigami.config.jpeg_sampling_factor)
      mogrify.interlace(Kirigami.config.jpeg_interlacing)
      mogrify.quality(Kirigami.config.jpeg_compression_quality)
    end
    mogrify << target_filepath
  end
end