Asset attribute

Attribute type idType specific restriction parameters
assetcontentTypes: List of valid media types. Wildcards are supported - i.e. "image/*".
maxFileSizeBytes: Maximum asset file size (in bytes).
colorModes: JSON array of valid color modes. Modes are extracted from EXIF ColorSpaceData or (if not present) Colorspace tags
minPixelWidth: Minimum asset width (in pixels)
minPixelHeight: Minimum asset height (in pixels)
maxPixelWidth: Maximum asset width (in pixels)
maxPixelHeight: Maximum asset height (in pixels)
minimumPixelLongEdge: Minimum length of longer edge (in pixels)
aspectRatio: Expected ratio, colon separated integer values - i.e. 16:10

Code Examples:

{
  "id" : "PRIMARY_IMAGE",
  "name" : "Primary image",
  "type" : {
    "id" : "asset",
    "restriction" : {
      "parameters" : {
        "colorModes" : "[\"RGB\",\"sRGB\"]",
        "maxPixelHeight" : "2160",
        "maxFileSizeBytes" : "1024000",
        "minPixelHeight" : "768",
        "minimumPixelLongEdge" : 1000
        "aspectRatio" : "[\"16:10\",\"4:3\",\"1:1\"]",
        "minPixelWidth" : "1024",
        "contentTypes" : "[\"image/jpeg\",\"image/png\"]",
        "maxPixelWidth" : "3840"
      }
    }
  }
}

"primaryAttributes": {
    "asset": "PRIMARY_IMAGE"
}
Attribute assetAttribute = AttributeBuilder
        .assetAttribute("PRIMARY_IMAGE", "Primary image")
        .withIsPrimaryImage(true)
        .withContentTypes(List.of(MediaType.JPEG))
        .withContentType(MediaType.PNG)
        .withMaxFileSize(1024_000)
        .withColorModes(List.of("RGB"))
        .withColorMode("sRGB")
        .withMinPixelWidth(1024)
        .withMinPixelHeight(768)
        .withMaxPixelWidth(3840)
        .withMaxPixelHeight(2160)
        .withAspectRatios(List.of(Ratio.of(16, 10), Ratio.of(4, 3)))
        .withAspectRatio(Ratio.of(1, 1))
        .build();

👍

One asset attribute should be set as a primary image.

This is the asset visible in product details, grid and list view.
This attribute should be attached to root category so it’s always available.
Asset can be marked as primary image with AssetAttributeBuilder#withIsPrimaryImage method.

📘

All restrictions are validated in provided order. Attribute validation will fail on the first unfulfilled restriction.

minPixelWidth, minPixelHeight, maxPixelWidth, maxPixelHeight, minimumPixelLongEdge and aspectRatio validations are only performed for image/* content types.