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:



23
24
25
26
27
28
29
30
# File 'lib/imgproxy/builder.rb', line 23

def initialize(options = {})
  options = options.dup

  extract_builder_options(options)

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

Instance Method Details

#info_url_for(image) ⇒ String

Genrates imgproxy info URL

Parameters:

  • image (String, URI, Object)

    Source image URL or object applicable for the configured URL adapters

Returns:

  • (String)

    imgproxy info URL

See Also:



51
52
53
54
55
56
# File 'lib/imgproxy/builder.rb', line 51

def info_url_for(image)
  path = url(image)
  signature = sign_path(path)

  File.join(Imgproxy.config.endpoint.to_s, "info", signature, path)
end

#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:



38
39
40
41
42
43
# File 'lib/imgproxy/builder.rb', line 38

def url_for(image)
  path = [*processing_options, url(image, ext: @format)].join("/")
  signature = sign_path(path)

  File.join(Imgproxy.config.endpoint.to_s, signature, path)
end