Class: DerivativeRodeo::Services::ImageService Private

Inherits:
BaseService
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/derivative_rodeo/services/image_service.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ImageService

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ImageService.



15
16
17
18
19
20
# File 'lib/derivative_rodeo/services/image_service.rb', line 15

def initialize(path)
  super()
  @path = path
  # The first 23 characters of a file contains the magic.
  @initial_file_contents = File.read(@path, 23, 0)
end

Instance Attribute Details

#pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/derivative_rodeo/services/image_service.rb', line 13

def path
  @path
end

Instance Method Details

#convert(destination:, monochrome: false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert source image to image at destination path, inferring file type from destination file extension. In case of JP2 files, create intermediate file using OpenJPEG 2000 that ImageMagick can use. Only outputs monochrome output if monochrome is true, destination format is TIFF.

Parameters:

  • destination (String)

    Path to output / destination file

  • monochrome (Boolean) (defaults to: false)

    true if monochrome output, otherwise false



48
49
50
51
52
53
# File 'lib/derivative_rodeo/services/image_service.rb', line 48

def convert(destination:, monochrome: false)
  raise 'JP2 output not yet supported' if destination.end_with?('jp2')

  source = jp2? ? jp2_to_tiff(path) : path
  convert_image(source: source, destination: destination, monochrome: monochrome)
end

#jp2?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


22
23
24
# File 'lib/derivative_rodeo/services/image_service.rb', line 22

def jp2?
  @initial_file_contents.end_with?('ftypjp2')
end

#technical_metadataDerivative::Rodeo::TechnicalMetadata Also known as: metadata

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Derivative::Rodeo::TechnicalMetadata)


27
28
29
30
31
32
33
34
35
# File 'lib/derivative_rodeo/services/image_service.rb', line 27

def 
  return @technical_metadata if defined?(@technical_metadata)

  @technical_metadata = if jp2?
                          ImageJp2Service.(path: path)
                        else
                          ImageIdentifyService.(path: path)
                        end
end