class Components::Assets::ImageAsset

Overview

Image asset with optimization capabilities

Defined in:

components/assets/base/image_asset.cr

Constant Summary

SUPPORTED_FORMATS = ["jpg", "jpeg", "png", "gif", "webp", "svg", "ico"] of ::String

Supported image formats

Constructors

Instance Method Summary

Instance methods inherited from class Components::Assets::Asset

add_dependency(asset_id : String) : Nil add_dependency, content : String content, content=(content : String) content=, content_type : String content_type, dependencies : Array(String) dependencies, fingerprint : String fingerprint, get_metadata(key : String) : String | Nil get_metadata, id : String id, metadata : Hash(String, String) metadata, modified? : Bool modified?, output_filename : String output_filename, process : String process, processed_content : String processed_content, reload : Nil reload, remove_dependency(asset_id : String) : Nil remove_dependency, set_metadata(key : String, value : String) : Nil set_metadata, source_path? : String | Nil source_path?, to_h : Hash(String, JSON::Any) to_h, updated_at : Time updated_at

Constructor methods inherited from class Components::Assets::Asset

new(source_path : String | Nil = nil, content : String = "") new

Constructor Detail

def self.new(source_path : String) #

[View source]

Instance Method Detail

def blur_placeholder : String #

Generate blur placeholder (simplified)


[View source]
def content_type : String #
Description copied from class Components::Assets::Asset

Abstract method - must be implemented by subclasses


[View source]
def dimensions : Tuple(Int32, Int32) | Nil #

Get image dimensions (placeholder)


[View source]
def format : String | Nil #

[View source]
def format=(format : String | Nil) #

[View source]
def height : Int32 | Nil #

[View source]
def height=(height : Int32 | Nil) #

[View source]
def lazy_load? : Bool #

Check if image should be lazy loaded


[View source]
def picture_element(sizes : String = "100vw", loading : String = "lazy", alt : String = "", class_name : String | Nil = nil) : String #

Generate picture element for responsive images


[View source]
def process : String #

Process image (optimization would happen here)


[View source]
def responsive_set(sizes : Array(Int32)) : Hash(Int32, String) #

Generate responsive image set


[View source]
def to_data_uri : String | Nil #

Convert to base64 data URI


[View source]
def width : Int32 | Nil #

Image-specific metadata


[View source]
def width=(width : Int32 | Nil) #

Image-specific metadata


[View source]