Class MediaFile
This class represents references to media content (such as images) located within Commerce Cloud Digital or on external systems.
Parameter transform:
Some methods allow the specification of image transformation parameters. Image transformation is only performed if the Dynamic Imaging Service (DIS) is available for the Commerce Cloud Digital instance, otherwise a standard static content URL is returned. The to-be-transformed image needs to be hosted on Commerce Cloud Digital.
Image transformation parameters are specified as JavaScript object literal. They are translated into URL parameters. See Create Image Transformation URLs.
| Type of transformation | Parameters | Description |
|---|---|---|
| Scale an image | scaleWidthscaleHeightscaleMode | The scaleWidth and scaleHeight parameters are both integers; setting one of these parameters triggers a scaling operation. If both are provided, the one that scales the image less is used to calculate the scale factor. The image is then automatically cropped accord to the second dimension, with a centered position of the cropped area. If the parameter would scale the image larger, only this operation is applied, if the image remains within acceptable pixel dimensions. Note: The |
| Overlay an image | imageXimageYimageURI | The imageX and imageY parameters are both integers. Valid values for these parameters are 0 or greater. Supported formats are The If the overlaid image extends over the primary image's boundaries, the overlaid image is cropped so that it fits directly over the primary image. |
| Crop an image | cropXcropYcropWidthcropHeight | The cropX, cropY, cropWidth, cropHeight parameters are integers. All four parameters must be specified to trigger a cropping operation. Valid values for the Valid values for the |
| Format an image | format | The format parameter specifies the target format of image. Supported formats are png, jpg, jp2, and gif. If no target format is specified, no format conversion is performed. The attribute value must reference the source image. Source image's format is recognized by the file extension which must be In the generated URL the file extension of the target format is used in the URL path. This is to make sure the image is loaded from an URL with a matching file extension. The source format is provided as URL parameter. |
| Adjust image compression quality | quality | The quality parameter specifies a quality setting for jpg and jp2 images, and specifies the compression level for png images. For For If the |
| Adjust Metadata stripping | strip | The strip parameter specifies if metadata like EXIF and color profiles is stripped from the image during transformation. Valid values for the |
| Change background color | bgcolor(color) or bgcolor(color+alpha) | The bgcolor parameter specifies the background color for images that support transparency as well as JPEG images when being converted from a format that supports transparency. Optionally, alpha setting for PNG images are also supported. FF0000 = Red FF000077 = Red with 50% transparency Alpha values are optional. When the alpha value is omitted, the resulting color is opaque. Alpha values are only valid when the image output format is PNG. |
Example:
The following code
var url = product.getImage('thumbnail', 0).getImageURL({scaleWidth: 100, format: 'jpg'});
will produce an image transformation URL like
http://<image server host name>/.../on/demandware.static/.../<path to image>/image.jpg?sw=100&sfrm=png.
| Property | Description |
|---|---|
URL: URL (read-only) | Returns an URL to the referenced media file. |
absURL: URL (read-only) | Returns an absolute URL to the referenced media file. |
alt: String (read-only) | Returns the alternative text assigned to the media file in current requests locale. |
httpURL: URL (read-only) | Returns an absolute URL to the referenced media file. |
httpsURL: URL (read-only) | Returns an absolute URL to the referenced media file. |
title: String (read-only) | Returns the title assigned to the media file in current requests locale. |
(read-only) | Returns an URL to the referenced media file. |
viewType: String (read-only) | Returns the view type annotation for the media file. |
This class does not have a constructor, so you cannot create it directly.
| Method | Description |
|---|---|
| getAbsImageURL(Object) | Returns an URL to the referenced image file. |
| getAbsURL() | Returns an absolute URL to the referenced media file. |
| getAlt() | Returns the alternative text assigned to the media file in current requests locale. |
| getHttpImageURL(Object) | Returns an URL to the referenced image file. |
| getHttpURL() | Returns an absolute URL to the referenced media file. |
| getHttpsImageURL(Object) | Returns an URL to the referenced image file. |
| getHttpsURL() | Returns an absolute URL to the referenced media file. |
| getImageURL(Object) | Returns an URL to the referenced image file. |
| getTitle() | Returns the title assigned to the media file in current requests locale. |
| getURL() | Returns an URL to the referenced media file. |
| Returns an URL to the referenced media file. | |
| getViewType() | Returns the view type annotation for the media file. |
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
- URL: URL
(read-only) Returns an URL to the referenced media file. The returned URL is a relative URL.
- absURL: URL
(read-only) Returns an absolute URL to the referenced media file. The protocol for the reference is the current protocol of the current HTTP request.
- alt: String
(read-only) Returns the alternative text assigned to the media file in current requests locale. If no alternative text was assigned or if no defaulting rule was defined, the method returns null.
- httpURL: URL
(read-only) Returns an absolute URL to the referenced media file. The protocol is http.
- httpsURL: URL
(read-only) Returns an absolute URL to the referenced media file. The protocol is https.
- title: String
(read-only) Returns the title assigned to the media file in current requests locale. If no title was assigned or if no defaulting rule was defined, the method returns null.
url: URL(read-only)Returns an URL to the referenced media file. The returned URL is a relative URL.
Deprecated:
Use getURL() instead.
- viewType: String
(read-only) Returns the view type annotation for the media file. The method returns null, if the media file has no view type annotation.
- getAbsImageURL(transform: Object): URL
Returns an URL to the referenced image file. Image transformation can be applied to the image. The protocol for the reference is the current protocol of the current HTTP request.
Image transformation can only be applied to images that are hosted on Commerce Cloud Digital.
Parameters:
- transform - Object with transformation parameters (see class header)
Returns:
- an absolute URL to the referenced media file. The protocol for the reference is the current protocol of the current HTTP request. If the referenced media file is hosted externally, an URL to the external file is returned.
- getAbsURL(): URL
Returns an absolute URL to the referenced media file. The protocol for the reference is the current protocol of the current HTTP request.
Returns:
- an absolute URL to the referenced media file. The protocol for the reference is the current protocol of the current HTTP request.
- getAlt(): String
Returns the alternative text assigned to the media file in current requests locale. If no alternative text was assigned or if no defaulting rule was defined, the method returns null.
Returns:
- the alternative text annotated to this media file or null
- getHttpImageURL(transform: Object): URL
Returns an URL to the referenced image file. Image transformation can be applied to the image. The protocol is http.
Image transformation can only be applied to images that are hosted on Commerce Cloud Digital.
Parameters:
- transform - Object with transformation parameters (see class header)
Returns:
- an absolute URL to the referenced media file. The protocol is http. If the referenced media file is hosted externally, an URL to the external file is returned.
- getHttpURL(): URL
Returns an absolute URL to the referenced media file. The protocol is http.
Returns:
- an absolute URL to the referenced media file. The protocol is http.
- getHttpsImageURL(transform: Object): URL
Returns an URL to the referenced image file. Image transformation can be applied to the image. The protocol is https.
Image transformation can only be applied to images that are hosted on Commerce Cloud Digital.
Parameters:
- transform - Object with transformation parameters (see class header)
Returns:
- an absolute URL to the referenced media file. The protocol is https. If the referenced media file is hosted externally, an URL to the external file is returned.
- getHttpsURL(): URL
Returns an absolute URL to the referenced media file. The protocol is https.
Returns:
- an absolute URL to the referenced media file. The protocol is https.
- getImageURL(transform: Object): URL
Returns an URL to the referenced image file. Image transformation can be applied to the image.
Image transformation can only be applied to images that are hosted on Commerce Cloud Digital.
Parameters:
- transform - Object with transformation parameters (see class header)
Returns:
- an URL to the referenced media file. The returned URL is a relative URL. If the referenced media file is hosted externally, an URL to the external file is returned.
- getTitle(): String
Returns the title assigned to the media file in current requests locale. If no title was assigned or if no defaulting rule was defined, the method returns null.
Returns:
- the title annotated to this media file or null
- getURL(): URL
Returns an URL to the referenced media file. The returned URL is a relative URL.
Returns:
- an URL to the referenced media file. The returned URL is a relative URL.
getUrl(): URLReturns an URL to the referenced media file. The returned URL is a relative URL.
Returns:
- an URL to the referenced media file. The returned URL is a relative URL.
Deprecated:
Use getURL() instead.
- getViewType(): String
Returns the view type annotation for the media file. The method returns null, if the media file has no view type annotation.
Returns:
- the view type annotated to this media file or null