Class: Imgproxy::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/imgproxy/builder.rb

Overview

Builds imgproxy URL

builder = Imgproxy::Builder.new(
width: 500,
height: 400,
resizing_type: :fill,
sharpen: 0.5
)

builder.url_for("http://images.example.com/images/image1.jpg")
builder.url_for("http://images.example.com/images/image2.jpg")

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Builder

Returns a new instance of Builder.

Parameters:

  • options (Hash) (defaults to: {})

    Processing options

See Also:



21
22
23
24
25
26
# File 'lib/imgproxy/builder.rb', line 21

def initialize(options = {})
  @use_short_options = options.delete(:use_short_options)
  @use_short_options = config.use_short_options if @use_short_options.nil?

  @options = Imgproxy::Options.new(options)
end

Instance Method Details

#url_for(image) ⇒ String

Genrates imgproxy URL

Parameters:

  • image (String, URI, Object)

    Source image URL or object applicable for the configured URL adapters

Returns:

  • (String)

    imgproxy URL

See Also:



34
35
36
37
38
39
40
41
# File 'lib/imgproxy/builder.rb', line 34

def url_for(image)
  path = [*processing_options, "plain", url(image)].join("/")
  path = "#{path}@#{@options[:format]}" if @options[:format]

  signature = sign_path(path)

  "#{Imgproxy.config.endpoint}/#{signature}/#{path}"
end