Module: Imgproxy

Defined in:
lib/imgproxy.rb,
lib/imgproxy/config.rb,
lib/imgproxy/builder.rb,
lib/imgproxy/options.rb,
lib/imgproxy/version.rb,
lib/imgproxy/trim_array.rb,
lib/imgproxy/url_adapters.rb,
lib/imgproxy/options_aliases.rb,
lib/imgproxy/extensions/shrine.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/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/gravity.rb,
lib/imgproxy/options_casters/integer.rb,
lib/imgproxy/extensions/active_storage.rb,
lib/imgproxy/options_casters/watermark.rb,
lib/imgproxy/options_casters/gif_options.rb,
lib/imgproxy/options_casters/png_options.rb,
lib/imgproxy/url_adapters/active_storage.rb,
lib/imgproxy/options_casters/jpeg_options.rb

Overview

See Also:

  • ClassMethods

Defined Under Namespace

Modules: Extensions, OptionsCasters, TrimArray Classes: Builder, Config, Options, UrlAdapters

Constant Summary collapse

VERSION =
"2.0.0".freeze
OPTIONS_ALIASES =
{
  resize: :rs,
  size: :s,
  resizing_type: :rt,
  resizing_algorithm: :ra,
  width: :w,
  height: :h,
  enlarge: :en,
  extend: :ex,
  gravity: :g,
  crop: :c,
  padding: :pd,
  trim: :t,
  rotate: :rot,
  quality: :q,
  max_bytes: :mb,
  background: :bg,
  background_alpha: :bga,
  adjust: :a,
  brightness: :br,
  contrast: :co,
  saturation: :sa,
  blur: :bl,
  sharpen: :sh,
  pixelate: :pix,
  unsharpening: :ush,
  watermark: :wm,
  watermark_url: :wmu,
  style: :st,
  jpeg_options: :jpego,
  png_options: :pngo,
  gif_options: :gifo,
  page: :pg,
  video_thumbnail_second: :vts,
  preset: :pr,
  cachebuster: :cb,
  strip_metadata: :sm,
  strip_color_profile: :scp,
  auto_rotate: :ar,
  filename: :fn,
}.freeze

Class Method Summary collapse

Class Method Details

.configConfig

Imgproxy config

Returns:



14
15
16
# File 'lib/imgproxy.rb', line 14

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:



29
30
31
32
# File 'lib/imgproxy.rb', line 29

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



128
129
130
131
132
133
134
135
# File 'lib/imgproxy.rb', line 128

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



139
140
141
142
143
144
# File 'lib/imgproxy.rb', line 139

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")

Parameters:

  • image (String, URI, Object)

    Source image URL or object applicable for the configured URL adapters

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

    Processing options

Options Hash (options):

  • :base64_encode_urls (Boolean)
  • :escape_plain_url (Boolean)

Returns:

  • (String)

    imgproxy info URL



122
123
124
# File 'lib/imgproxy.rb', line 122

def info_url_for(image, options = {})
  Imgproxy::Builder.new(options).info_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

Options Hash (options):

  • :resize (Hash|Array|String)
  • :size (Hash|Array|String)
  • :resizing_type (String)
  • :resizing_algorithm (String)

    supported only by imgproxy pro

  • :width (Integer)
  • :height (Integer)
  • :dpr (Float)
  • :enlarge (Boolean)
  • :extend (Hash|Array|Boolean|String)
  • :gravity (Hash|Array|String)
  • :crop (Hash|Array|String)
  • :padding (Array)
  • :trim (Hash|Array|String)
  • :rotate (Integer)
  • :quality (Integer)
  • :max_bytes (Integer)
  • :background (Array|String)
  • :background_alpha (Float)

    supported only by imgproxy pro

  • :adjust (Hash|Array|String)
  • :brightness (Integer)

    supported only by imgproxy pro

  • :contrast (Float)

    supported only by imgproxy pro

  • :saturation (Float)

    supported only by imgproxy pro

  • :blur (Float)
  • :sharpen (Float)
  • :pixelate (Integer)

    supported only by imgproxy pro

  • :unsharpening (String)

    supported only by imgproxy pro

  • :watermark (Hash|Array|Float|String)
  • :watermark_url (String)

    supported only by imgproxy pro

  • :style (String)

    supported only by imgproxy pro

  • :jpeg_options (Hash|Array|String)

    supported only by imgproxy pro

  • :png_options (Hash|Array|String)

    supported only by imgproxy pro

  • :gif_options (Hash|Array|String)

    supported only by imgproxy pro

  • :page (Integer)

    supported only by imgproxy pro

  • :video_thumbnail_second (Integer)

    supported only by imgproxy pro

  • :preset (Array)
  • :cachebuster (String)
  • :strip_metadata (Boolean)
  • :strip_color_profile (Boolean)
  • :auto_rotate (Boolean)
  • :filename (String)
  • :format (String)
  • :use_short_options (Boolean)
  • :base64_encode_urls (Boolean)
  • :escape_plain_url (Boolean)

Returns:

  • (String)

    imgproxy URL

See Also:



108
109
110
# File 'lib/imgproxy.rb', line 108

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