Class: Assembly::Image
- Inherits:
-
ObjectFile
- Object
- ObjectFile
- Assembly::Image
- Defined in:
- lib/assembly/image.rb,
lib/assembly/image/jp2_creator.rb
Overview
The Image class contains methods to operate on an image.
Defined Under Namespace
Classes: Jp2Creator
Instance Method Summary collapse
-
#create_jp2(**params) ⇒ Assembly::Image
Create a JP2 file for the current image.
-
#extract_first_page(output_path) ⇒ Object
Extract and save only the first page from a multi-image TIFF.
-
#has_profile? ⇒ Boolean
Does the image include an ICC profile?.
-
#height ⇒ integer
Image height in pixels.
-
#jp2_filename ⇒ string
Example: given original file of ‘/dir/path_to_file.tif’, gives ‘/dir/path_to_file.jp2’.
-
#multi_page? ⇒ boolean
True if this image is a multi-page (e.g. a TIFF with multiple pages).
- #srgb? ⇒ Boolean
- #vips_image ⇒ Object
-
#width ⇒ integer
Image width in pixels.
Instance Method Details
#create_jp2(**params) ⇒ Assembly::Image
60 61 62 |
# File 'lib/assembly/image.rb', line 60 def create_jp2(**params) Jp2Creator.create(self, **params) end |
#extract_first_page(output_path) ⇒ Object
Extract and save only the first page from a multi-image TIFF
31 32 33 34 35 36 37 38 |
# File 'lib/assembly/image.rb', line 31 def extract_first_page(output_path) raise "Cannot extract first page from mimetype #{mimetype}" unless mimetype == 'image/tiff' first_page = Vips::Image.new_from_file(path, page: 0).autorot first_page.write_to_file(output_path) true end |
#has_profile? ⇒ Boolean
Does the image include an ICC profile?
76 77 78 |
# File 'lib/assembly/image.rb', line 76 def has_profile? vips_image.get_fields.include?('icc-profile-data') end |
#height ⇒ integer
Returns image height in pixels.
11 12 13 |
# File 'lib/assembly/image.rb', line 11 def height vips_image.height end |
#jp2_filename ⇒ string
Example: given original file of ‘/dir/path_to_file.tif’, gives ‘/dir/path_to_file.jp2’
42 43 44 45 |
# File 'lib/assembly/image.rb', line 42 def jp2_filename # path is a property on Assembly::ObjectFile File.extname(path).empty? ? "#{path}.jp2" : path.gsub(File.extname(path), '.jp2') end |
#multi_page? ⇒ boolean
Returns true if this image is a multi-page (e.g. a TIFF with multiple pages).
21 22 23 24 25 26 27 |
# File 'lib/assembly/image.rb', line 21 def multi_page? return false unless mimetype == 'image/tiff' vips_image.get('n-pages').to_i > 1 rescue Vips::Error false end |
#srgb? ⇒ Boolean
71 72 73 |
# File 'lib/assembly/image.rb', line 71 def srgb? vips_image.interpretation == :srgb end |
#vips_image ⇒ Object
64 65 66 67 68 69 |
# File 'lib/assembly/image.rb', line 64 def vips_image # Disable cache. Otherwise, Vips gets confused by files with the same filename. Vips.cache_set_max_files(0) # autorot will only affect images that need rotation: https://www.libvips.org/API/current/libvips-conversion.html#vips-autorot @vips_image ||= Vips::Image.new_from_file(path).autorot end |
#width ⇒ integer
Returns image width in pixels.
16 17 18 |
# File 'lib/assembly/image.rb', line 16 def width vips_image.width end |