Class: Kirigami::Image
- Inherits:
-
Object
- Object
- Kirigami::Image
- Defined in:
- lib/kirigami/image.rb
Overview
An Image file to be compressed and cut via Kirigami
Instance Attribute Summary collapse
-
#max_size ⇒ Object
readonly
An ImageMagick Image Geometry for the target file size http://www.imagemagick.org/script/command-line-processing.php#geometry.
-
#path ⇒ Object
readonly
The filepath of the image to be cut.
Instance Method Summary collapse
-
#backup_filename ⇒ Object
private
The filename for the backup File.
-
#backup_filepath ⇒ Object
private
The absolute filepath for the backup File.
-
#create_backup_copy ⇒ Object
private
Create a backup copy of the File first.
-
#cut! ⇒ Object
Cuts the File down to size! Creates a backup copy first, if required.
-
#filename ⇒ Object
private
The filename for the target File.
-
#initialize(path, max_size) ⇒ Image
constructor
Create a new Image.
-
#jpeg? ⇒ Boolean
private
Is the target File a JPEG?.
-
#target_filepath ⇒ Object
private
The absolute filepath for the target File.
Constructor Details
#initialize(path, max_size) ⇒ Image
Create a new 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_size ⇒ Object (readonly)
An ImageMagick Image Geometry for the target file size http://www.imagemagick.org/script/command-line-processing.php#geometry
10 11 12 |
# File 'lib/kirigami/image.rb', line 10 def max_size @max_size end |
#path ⇒ Object (readonly)
The filepath of the image to be cut
17 18 19 |
# File 'lib/kirigami/image.rb', line 17 def path @path end |
Instance Method Details
#backup_filename ⇒ Object (private)
The filename for the backup File. Uses #filename + ".BAK"
69 70 71 |
# File 'lib/kirigami/image.rb', line 69 def backup_filename File.basename(path) + ".BAK" end |
#backup_filepath ⇒ Object (private)
The absolute filepath for the backup File
76 77 78 |
# File 'lib/kirigami/image.rb', line 76 def backup_filepath File.join(File.dirname(path), backup_filename) end |
#create_backup_copy ⇒ Object (private)
Create a backup copy of the File first
48 49 50 |
# File 'lib/kirigami/image.rb', line 48 def create_backup_copy FileUtils.cp(target_filepath, backup_filepath) if Kirigami.config.safe_mode end |
#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 |
#filename ⇒ Object (private)
The filename for the target File
62 63 64 |
# File 'lib/kirigami/image.rb', line 62 def filename File.basename(path) end |
#jpeg? ⇒ Boolean (private)
Is the target File a JPEG?
83 84 85 |
# File 'lib/kirigami/image.rb', line 83 def jpeg? filename.ends_with?(".jpg") end |
#target_filepath ⇒ Object (private)
The absolute filepath for the target File
55 56 57 |
# File 'lib/kirigami/image.rb', line 55 def target_filepath File.join(File.dirname(path), filename) end |