Module: Imgproxy

Defined in:
lib/imgproxy.rb,
lib/imgproxy/config.rb,
lib/imgproxy/version.rb,
lib/imgproxy/trim_array.rb,
lib/imgproxy/url_adapters.rb,
lib/imgproxy/service_config.rb,
lib/imgproxy/extensions/shrine.rb,
lib/imgproxy/url_builders/base.rb,
lib/imgproxy/url_builders/info.rb,
lib/imgproxy/option_aliases/info.rb,
lib/imgproxy/url_adapters/shrine.rb,
lib/imgproxy/options_casters/bool.rb,
lib/imgproxy/options_casters/crop.rb,
lib/imgproxy/options_casters/size.rb,
lib/imgproxy/options_casters/trim.rb,
lib/imgproxy/options_casters/zoom.rb,
lib/imgproxy/options_builders/base.rb,
lib/imgproxy/options_builders/info.rb,
lib/imgproxy/options_casters/alpha.rb,
lib/imgproxy/options_casters/array.rb,
lib/imgproxy/options_casters/float.rb,
lib/imgproxy/options_casters/group.rb,
lib/imgproxy/options_casters/adjust.rb,
lib/imgproxy/options_casters/base64.rb,
lib/imgproxy/options_casters/extend.rb,
lib/imgproxy/options_casters/resize.rb,
lib/imgproxy/options_casters/string.rb,
lib/imgproxy/options_casters/average.rb,
lib/imgproxy/options_casters/gravity.rb,
lib/imgproxy/options_casters/hashsum.rb,
lib/imgproxy/options_casters/integer.rb,
lib/imgproxy/options_casters/padding.rb,
lib/imgproxy/url_builders/processing.rb,
lib/imgproxy/options_casters/blurhash.rb,
lib/imgproxy/options_casters/filename.rb,
lib/imgproxy/options_casters/gradient.rb,
lib/imgproxy/extensions/active_storage.rb,
lib/imgproxy/option_aliases/processing.rb,
lib/imgproxy/options_casters/watermark.rb,
lib/imgproxy/options_casters/background.rb,
lib/imgproxy/options_builders/processing.rb,
lib/imgproxy/options_casters/autoquality.rb,
lib/imgproxy/options_casters/png_options.rb,
lib/imgproxy/url_adapters/active_storage.rb,
lib/imgproxy/options_casters/jpeg_options.rb,
lib/imgproxy/options_casters/webp_options.rb,
lib/imgproxy/options_casters/format_quality.rb,
lib/imgproxy/options_casters/watermark_size.rb,
lib/imgproxy/options_casters/blur_detections.rb,
lib/imgproxy/options_casters/dominant_colors.rb,
lib/imgproxy/options_casters/draw_detections.rb,
lib/imgproxy/options_casters/unsharp_masking.rb,
lib/imgproxy/options_casters/video_thumbnail_tile.rb

Overview

See Also:

  • ClassMethods

Defined Under Namespace

Modules: Extensions, OptionAliases, OptionsBuilders, OptionsCasters, TrimArray, UrlBuilders Classes: Config, ServiceConfig, UrlAdapters

Constant Summary collapse

VERSION =
"3.0.0"

Class Method Summary collapse

Class Method Details

.configConfig

Imgproxy config

Returns:



17
18
19
# File 'lib/imgproxy.rb', line 17

def config
  @config ||= Imgproxy::Config.new
end

.configure {|config| ... } ⇒ Config

Yields Imgproxy config

Imgproxy.configure do |config|
  config.endpoint = "http://imgproxy.example.com"
  config.key = "your_key"
  config.salt = "your_salt"
  config.use_short_options = true
end

Yield Parameters:

Returns:



32
33
34
35
# File 'lib/imgproxy.rb', line 32

def configure
  yield config
  config
end

.extend_active_storage!Object

Extends ActiveStorage::Blob with Imgproxy::Extensions::ActiveStorage#imgproxy_url method and adds URL adapters for ActiveStorage



92
93
94
95
96
97
98
99
# File 'lib/imgproxy.rb', line 92

def extend_active_storage!
  return unless defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load)

  ActiveSupport.on_load(:active_storage_blob) do
    ::ActiveStorage::Blob.include Imgproxy::Extensions::ActiveStorage
    Imgproxy.config.url_adapters.add(Imgproxy::UrlAdapters::ActiveStorage.new)
  end
end

.extend_shrine!Object

Extends Shrine::UploadedFile with Imgproxy::Extensions::Shrine#imgproxy_url method and adds URL adapters for Shrine



103
104
105
106
107
108
# File 'lib/imgproxy.rb', line 103

def extend_shrine!
  return unless defined?(::Shrine::UploadedFile)

  ::Shrine::UploadedFile.include Imgproxy::Extensions::Shrine
  Imgproxy.config.url_adapters.add(Imgproxy::UrlAdapters::Shrine.new)
end

.info_url_for(image, options = {}) ⇒ String

Genrates imgproxy info URL. Supported only by imgproxy Pro

Imgproxy.info_url_for(
  "http://images.example.com/images/image.jpg",
  alpha: {
    alpha: true,
    check_transparency: true
  },
  palette: 128,
)

Parameters:

  • image (String, URI, Object)

    Source image URL or object applicable for the configured URL adapters

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

    Info options. See: Supported info options

Returns:

  • (String)

    imgproxy info URL



86
87
88
# File 'lib/imgproxy.rb', line 86

def info_url_for(image, options = {})
  Imgproxy::UrlBuilders::Info.new(options).url_for(image)
end

.url_for(image, options = {}) ⇒ String

Genrates imgproxy URL

Imgproxy.url_for(
  "http://images.example.com/images/image.jpg",
  width: 500,
  height: 400,
  resizing_type: :fill,
  sharpen: 0.5,
  gravity: {
    type: :soea,
    x_offset: 10,
    y_offset: 5,
  },
  crop: {
    width: 2000,
    height: 1000,
    gravity: {
      type: :nowe,
      x_offset: 20,
      y_offset: 30,
    },
  },
)

Parameters:

  • image (String, URI, Object)

    Source image URL or object applicable for the configured URL adapters

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

    Processing options. See: Supported processing options

Returns:

  • (String)

    imgproxy URL



66
67
68
# File 'lib/imgproxy.rb', line 66

def url_for(image, options = {})
  Imgproxy::UrlBuilders::Processing.new(options).url_for(image)
end