Class: Assembly::Image

Inherits:
ObjectFile
  • Object
show all
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

Instance Method Details

#create_jp2(**params) ⇒ Assembly::Image

Create a JP2 file for the current image. Important note: this will not work for multipage TIFFs.

Example:

source_img = Assembly::Image.new('/dir/path_to_file.tif')
jp2_img = source_img.create_jp2(overwrite: true)
jp2_img.mimetype # 'image/jp2'
jp2_img.path # '/dir/path_to_file.jp2'


40
41
42
# File 'lib/assembly/image.rb', line 40

def create_jp2(**params)
  Jp2Creator.create(self, **params)
end

#has_profile?Boolean

Does the image include an ICC profile?



56
57
58
# File 'lib/assembly/image.rb', line 56

def has_profile?
  vips_image.get_fields.include?('icc-profile-data')
end

#heightinteger



11
12
13
# File 'lib/assembly/image.rb', line 11

def height
  vips_image.height
end

#jp2_filenamestring

Example: given original file of ‘/dir/path_to_file.tif’, gives ‘/dir/path_to_file.jp2’



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

def jp2_filename
  # path is a property on Assembly::ObjectFile
  File.extname(path).empty? ? "#{path}.jp2" : path.gsub(File.extname(path), '.jp2')
end

#srgb?Boolean



51
52
53
# File 'lib/assembly/image.rb', line 51

def srgb?
  vips_image.interpretation == :srgb
end

#vips_imageObject



44
45
46
47
48
49
# File 'lib/assembly/image.rb', line 44

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

#widthinteger



16
17
18
# File 'lib/assembly/image.rb', line 16

def width
  vips_image.width
end