# Image and asset URL filters

Filters that build asset and media URLs and transform images on the fly.

These filters build URLs for assets, media files and storefront resources, and transform images on the fly. They complement the [URL filters](https://developer.versacommerce.de/articles/liquid-filters-url-filters).

Image transformation filters work on an image URL and can be chained:

```liquid
{{ product.featured_image | image_url | resize: '400x400' | quality: 80 }}
```

## Asset and file URLs

### assets_root

Returns the current Liquid filesystem's asset root.

Parameters: no Ruby arguments.

### versacommerce_asset_url

Builds a shared compatibility asset path.

Parameters: filename as input.

Example: `{{ 'option_selection.js' | versacommerce_asset_url }}` returns `/static_assets/alien/option_selection.js`.

### cdn_url

Passes through the supplied URL.

Example: `{{ url | cdn_url }}` returns the same URL.

### global_asset_path

Builds the global asset path.

Parameters: filename as input.

Example: `{{ 'theme.js' | global_asset_path }}` returns `/global/theme.js`.

### app_asset_url

Resolves an application-shipped asset.

Parameters: repository public path as input.

Example: `{{ '/assets/public.css' | app_asset_url }}` returns the application asset URL.

### static_assets_path

Builds a static asset path with a version when available.

Parameters: relative path as input.

Example: `{{ 'missing_image.svg' | static_assets_path }}` returns `/static_assets/missing_image.svg`, optionally with a `?v=` timestamp.

### static_assets_url

Alias for static_assets_path.

Parameters: relative path as input.

Example: `{{ 'missing_image.svg' | static_assets_url }}` returns the static asset path.

### asset_path

Resolves a theme asset; asset_url is its alias.

Parameters: filename as input.

Example: `{{ 'theme.css' | asset_path }}` returns the theme asset URL.

### dynamic_cdn_url

Resolves a sharded CDN URL.

Parameters: optional CDN count, default 4.

Example: `{{ url | dynamic_cdn_url }}` returns the CDN URL.

### media_image_path

Builds the shop's uploaded-image URL.

Parameters: filename as input.

Example: `{{ 'logo.png' | media_image_path }}` returns `//<asset-host>/<shop>/mediafiles/images/logo.png`.

### media_image_url

Alias for media_image_path.

Parameters: filename as input.

Example: `{{ 'logo.png' | media_image_url }}` returns the uploaded-image URL.

### media_movie_path

Builds the uploaded-video URL.

Parameters: filename as input.

Example: `{{ 'demo.mp4' | media_movie_path }}` returns `//<asset-host>/<shop>/mediafiles/videos/demo.mp4`.

### media_movie_url

Alias for media_movie_path.

Parameters: filename as input.

Example: `{{ 'demo.mp4' | media_movie_url }}` returns the uploaded-video URL.

### media_document_path

Builds the uploaded-document URL.

Parameters: filename as input.

Example: `{{ 'guide.pdf' | media_document_path }}` returns `//<asset-host>/<shop>/mediafiles/documents/guide.pdf`.

### media_document_url

Alias for media_document_path.

Parameters: filename as input.

Example: `{{ 'guide.pdf' | media_document_url }}` returns the uploaded-document URL.

## Resource URLs

### url_for

Resolves the URL for a tag.

Parameters: tag as input.

Example: `{{ tag | url_for }}` returns the tag URL.

### url_for_variant

Resolves a variant URL from its handle.

Parameters: variant handle as input.

Example: `{{ variant.handle | url_for_variant }}` returns the variant URL.

### article_img_url

Article-oriented alias for img_url.

Parameters: size or image options.

Example: `{{ article | article_img_url: 'medium' }}` returns the resized image URL.

### blog_img_url

Blog-oriented alias for img_url.

Parameters: size or image options.

Example: `{{ blog | blog_img_url: 'medium' }}` returns the resized image URL.

### page_img_url

Page-oriented alias for img_url.

Parameters: size or image options.

Example: `{{ page | page_img_url: 'medium' }}` returns the resized image URL.

### line_item_img_url

Line-item-oriented alias for img_url.

Parameters: size or image options.

Example: `{{ item | line_item_img_url: 'medium' }}` returns the resized image URL.

### gravatar_url

Builds a Gravatar URL.

Parameters: email as input, optional options.

Example: `{{ customer.email | gravatar_url }}` returns the Gravatar URL.

### additional_params

Merges query parameters into a URL.

Parameters: parameter hash.

Example: `{{ '/search' | additional_params: q: 'coat' }}` returns `/search?q=coat`.

### prepend_url_param

Prepends a URL parameter.

Parameters: parameter, optional value.

Example: `{{ url | prepend_url_param: 'width', 100 }}` returns the URL with the parameter prepended.

### customer_register_link

Builds a customer registration link.

Parameters: link label as input.

Example: `{{ 'Register' | customer_register_link }}` returns the registration anchor.

### customer_logout_link

Builds a customer logout link.

Parameters: link label as input.

Example: `{{ 'Log out' | customer_logout_link }}` returns the logout anchor.

## Image transformations

### resize

Sets an image resize transformation.

Parameters: resize string.

Example: `{{ url | resize: '200x200' }}` returns the transformed URL.

### canvas

Sets an image canvas transformation.

Parameters: canvas string.

Example: `{{ url | canvas: '0' }}` returns the transformed URL.

### cropmode

Sets image crop mode.

Parameters: mode.

Example: `{{ url | cropmode: mode }}` returns the transformed URL.

### smartcrop

Sets smart-crop transformation.

Parameters: smart-crop string.

Example: `{{ url | smartcrop: crop }}` returns the transformed URL.

### blur

Sets image blur.

Parameters: blur value.

Example: `{{ url | blur: '5' }}` returns the transformed URL.

### quality

Sets image quality.

Parameters: quality value.

Example: `{{ url | quality: '80' }}` returns the transformed URL.

### progressive

Requests progressive image output.

Example: `{{ url | progressive }}` returns the transformed URL.

### background

Sets an image background.

Parameters: background color.

Example: `{{ url | background: 'ffffff' }}` returns the transformed URL.

### convert_to

Requests an image output format.

Parameters: format.

Example: `{{ url | convert_to: 'png' }}` returns the transformed URL.

### refit

Sets the refit transformation.

Parameters: refit value.

Example: `{{ url | refit: value }}` returns the transformed URL.

### gravity

Sets image positioning gravity.

Parameters: gravity value.

Example: `{{ url | gravity: value }}` returns the transformed URL.

### scale

Sets image scale.

Parameters: scale value.

Example: `{{ url | scale: 2 }}` returns the transformed URL.

### image_max_size

Reads the maximum image size.

Parameters: no Ruby arguments.

### resize_param

Resolves named or explicit image dimensions.

Parameters: size as input.

Example: `{{ 'medium' | resize_param }}` returns the resize parameter.

## Host and scheme

### serve_from_host

Resolves a URL against the storefront host.

Example: `{{ '/cart' | serve_from_host }}` returns the storefront URL.

### force_http_scheme

Forces the HTTP URL scheme.

Example: `{{ url | force_http_scheme }}` returns the URL with the `http` scheme.

### force_https_scheme

Forces the HTTPS URL scheme.

Example: `{{ url | force_https_scheme }}` returns the URL with the `https` scheme.

### force_scheme

Uses a supplied URL scheme.

Parameters: scheme.

Example: `{{ url | force_scheme: 'https' }}` returns the URL with the given scheme.
