Module: DynamicImage

Defined in:
lib/dynamic_image.rb,
lib/dynamic_image/model.rb,
lib/dynamic_image/ratio.rb,
lib/dynamic_image/engine.rb,
lib/dynamic_image/errors.rb,
lib/dynamic_image/format.rb,
lib/dynamic_image/helper.rb,
lib/dynamic_image/schema.rb,
lib/dynamic_image/picture.rb,
lib/dynamic_image/routing.rb,
lib/dynamic_image/version.rb,
lib/dynamic_image/backfill.rb,
lib/dynamic_image/metadata.rb,
lib/dynamic_image/belongs_to.rb,
lib/dynamic_image/controller.rb,
lib/dynamic_image/breakpoints.rb,
lib/dynamic_image/image_reader.rb,
lib/dynamic_image/image_sizing.rb,
app/models/dynamic_image/variant.rb,
lib/dynamic_image/helper/formats.rb,
lib/dynamic_image/model/variants.rb,
lib/dynamic_image/digest_verifier.rb,
lib/dynamic_image/helper/pictures.rb,
lib/dynamic_image/image_processor.rb,
lib/dynamic_image/processed_image.rb,
lib/dynamic_image/model/dimensions.rb,
lib/dynamic_image/format_negotiator.rb,
lib/dynamic_image/model/validations.rb,
lib/dynamic_image/model/transformations.rb,
lib/dynamic_image/picture/format_policy.rb,
lib/dynamic_image/image_processor/colors.rb,
lib/dynamic_image/image_processor/frames.rb,
lib/dynamic_image/image_processor/transform.rb,
lib/rails/generators/dynamic_image/upgrade/upgrade_generator.rb,
lib/rails/generators/dynamic_image/resource/resource_generator.rb

Overview

A Rails engine for image uploads. Rather than creating a pre-defined set of images when a file is uploaded, it stores the original file and generates images on demand. It handles cropping, resizing, format and colorspace conversion, and stores each processed size as a variant.

Include Model in the model holding the image and Controller in the controller serving it, then declare the routes with Routing#image_resources. Views render images through the helpers in Helper, which sign the URLs.

Files are stored with Dis, and processing is done with libvips.

Defined Under Namespace

Modules: BelongsTo, Controller, Errors, Generators, Helper, Model, Ratio, Routing, Schema Classes: Backfill, Breakpoints, DigestVerifier, Engine, Format, FormatNegotiator, ImageProcessor, ImageReader, ImageSizing, Metadata, Picture, ProcessedImage, Variant

Constant Summary collapse

COMPATIBLE_FORMATS =

The formats anything that renders images will understand. Fallback images in a picture are negotiated from this list, and it is the default for #mailer_formats.

Returns:

  • the format names, most preferred first

%i[jpeg png gif].freeze
VERSION =
"3.1.3"

Instance Method Summary collapse

Instance Method Details

#breakpoint_stepFloat

The ratio between two breakpoints. Lower means a closer fit to what the browser needs, at the price of more variants to generate and store.

Returns:



79
# File 'lib/dynamic_image.rb', line 79

mattr_accessor :breakpoint_step, default: 1.4

#default_breakpointsRange, ...

The breakpoints responsive images are rendered at. This can be a range, an array of explicit widths, or a single width.

Returns:

See Also:



73
# File 'lib/dynamic_image.rb', line 73

mattr_accessor :default_breakpoints, default: 320..3200

#default_formatsArray<Symbol>

The formats a view accepts when it doesn't pass format:. Also decides what DynamicImage::Model#safe_content_type considers safe.

Returns:

  • the format names, most preferred first



61
# File 'lib/dynamic_image.rb', line 61

mattr_accessor :default_formats, default: %i[jpeg png gif webp]

#digest_verifierDynamicImage::DigestVerifier

Verifies the HMAC digests embedded in image URLs. Set by the engine from the application's key generator, which derives it from secret_key_base.

Returns:



55
# File 'lib/dynamic_image.rb', line 55

cattr_accessor :digest_verifier

#mailer_formatsArray<Symbol>

The formats a mailer view accepts when it doesn't pass format:.

Returns:

  • the format names, most preferred first



66
# File 'lib/dynamic_image.rb', line 66

mattr_accessor :mailer_formats, default: COMPATIBLE_FORMATS

#picture_fallback_widthInteger

The width of the fallback image in a picture element.

Returns:



84
# File 'lib/dynamic_image.rb', line 84

mattr_accessor :picture_fallback_width, default: 1200