Sha256: f3ed2fafd0d43bd38cc3204475796fe06a42bb47b0277d476eeb035f1e130557

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

require 'httpthumbnailer-client'
require 'httpimagestore/ruby_string_template'
require 'httpimagestore/configuration/handler'

module Configuration
	class Identify
		include ClassLogging

		extend Stats
		def_stats(
			:total_identify_requests, 
			:total_identify_requests_bytes
		)

		include ConditionalInclusion

		def self.match(node)
			node.name == 'identify'
		end

		def self.parse(configuration, node)
			image_name = node.grab_values('image name').first
			if_image_name_on = node.grab_attributes('if-image-name-on').first

			matcher = InclusionMatcher.new(image_name, if_image_name_on) if if_image_name_on

			configuration.processors << self.new(configuration.global, image_name, matcher)
		end

		def initialize(global, image_name, matcher = nil)
			@global = global
			@image_name = image_name
			inclusion_matcher matcher if matcher
		end

		def realize(request_state)
			client = @global.thumbnailer or fail 'thumbnailer configuration'
			image = request_state.images[@image_name]

			log.info "identifying '#{@image_name}'"

			Identify.stats.incr_total_identify_requests
			Identify.stats.incr_total_identify_requests_bytes image.data.bytesize

			id = client.identify(image.data)

			image.mime_type = id.mime_type if id.mime_type
			image.width = id.width if id.width
			image.height = id.height if id.height
			log.info "image '#{@image_name}' identified as '#{id.mime_type}' #{image.width}x#{image.height}"
		end
	end
	Handler::register_node_parser Identify
	StatsReporter << Identify.stats
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
httpimagestore-1.6.0 lib/httpimagestore/configuration/identify.rb
httpimagestore-1.5.0 lib/httpimagestore/configuration/identify.rb
httpimagestore-1.4.1 lib/httpimagestore/configuration/identify.rb
httpimagestore-1.4.0 lib/httpimagestore/configuration/identify.rb
httpimagestore-1.3.0 lib/httpimagestore/configuration/identify.rb