Class: Imgwire::Image
- Inherits:
-
ImgwireGenerated::ImageSchema
- Object
- ImgwireGenerated::ImageSchema
- Imgwire::Image
- Defined in:
- lib/imgwire/image.rb
Constant Summary collapse
- PRESETS =
%w[thumbnail small medium large].freeze
- ROTATE_ANGLES =
[0, 90, 180, 270, 360].freeze
- FORMATS =
%w[jpg png avif gif webp].freeze
- RULES =
{ 'background' => %w[background bg], 'crop' => %w[crop], 'enlarge' => %w[enlarge], 'format' => %w[format fm], 'gravity' => %w[gravity], 'height' => %w[height h], 'quality' => %w[quality q], 'rotate' => %w[rotate rot], 'strip_metadata' => %w[strip_metadata strip], 'width' => %w[width w] }.freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.wrap(value) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/imgwire/image.rb', line 24 def self.wrap(value) return value if value.is_a?(self) if value.is_a?(ImgwireGenerated::ImageSchema) attributes = ImgwireGenerated::ImageSchema.attribute_map.keys.to_h do |attribute| [attribute, value.public_send(attribute)] end return new(attributes) end return build_from_hash(value.to_hash) if value.respond_to?(:to_hash) build_from_hash(value) end |
Instance Method Details
#url(options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/imgwire/image.rb', line 38 def url( = {}) = symbolize_keys() path = build_preset_path([:preset]) query = build_query(.except(:preset)) uri = URI.parse(cdn_url) uri.path = path uri.query = query.empty? ? nil : URI.encode_www_form(query.sort_by(&:first)) uri.to_s end |