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'

Parameters:

  • output (String)

    path to the output JP2 file (default: mirrors the source file name and path, but with a .jp2 extension)

  • overwrite (Boolean)

    if set to false, an existing JP2 file with the same name won’t be overwritten (default: false)

  • tmp_folder (Dir)

    the temporary folder to use when creating the jp2 (default: ‘/tmp’); also used by imagemagick

Returns:



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?

Returns:

  • (Boolean)


54
55
56
# File 'lib/assembly/image.rb', line 54

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

#heightinteger

Returns image height in pixels.

Returns:

  • (integer)

    image height in pixels



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’

Returns:

  • (string)

    full default jp2 path and filename that will be created from the given image



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

Returns:

  • (Boolean)


49
50
51
# File 'lib/assembly/image.rb', line 49

def srgb?
  vips_image.interpretation == :srgb
end

#vips_imageObject



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

def vips_image
  # 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

Returns image width in pixels.

Returns:

  • (integer)

    image width in pixels



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

def width
  vips_image.width
end