Policy image

akamai_imaging_policy_image

Specify details for an image policy, like transformations to apply and variations in image size and formats. Then reference this data source in the corresponding resource.

See Transform images for a complete list of available transformations for an image policy. To define variables in your policy, see Use variables.

data "akamai_imaging_policy_image" "my-image-policy-definition" {
  policy {
    breakpoints {
      widths = [280, 1080]
    }
    hosts = ["www.example-1.com", "www.example-2.com"]
    output {
      adaptive_quality   = 50
      perceptual_quality = "mediumHigh"
    }
    transformations {
      region_of_interest_crop {
        gravity = "Center"
        height  = 8
        region_of_interest {
          rectangle_shape {
            anchor {
              x = 4
              y = 5
            }
            height = 9
            width  = 8
          }
        }
        style = "fill"
        width = 7
      }
    }
    transformations {
      append {
        gravity          = "Center"
        gravity_priority = "horizontal"
        image {
          text_image {
            fill        = "#000000"
            size        = 72
            stroke      = "#FFFFFF"
            stroke_size = 0
            text        = "test"
          }
        }
        preserve_minor_dimension = true
      }
    }
    transformations {
      trim {
        fuzz    = 0.08
        padding = 0
      }
    }
    transformations {
      if_dimension {
        default {
          resize {
            aspect     = "fit"
            height_var = "ResizeDim"
            type       = "normal"
            width_var  = "ResizeDim"
          }
        }
        dimension = "height"
        less_than {
          crop {
            allow_expansion = true
            gravity         = "Center"
            height_var      = "ResizeDim"
            width_var       = "ResizeDim"
            x_position      = 0
            y_position      = 0
          }
        }
        value_var = "MinDim"
      }
    }
    transformations {
      im_query {
        allowed_transformations = ["Append", "Blur", "Crop"]
        query_var               = "imq"
      }
    }
    variables {
      default_value = "280"
      name          = "ResizeDim"
      type          = "number"
    }
    variables {
      default_value = "1000"
      name          = "MinDim"
      type          = "number"
    }
    variables {
      default_value = ""
      name          = "imq"
      type          = "string"
    }
  }
}

output "my-image-policy" {
  value = data.akamai_imaging_policy_image.my-image-policy-definition
}

resource "akamai_imaging_policy_image" "my-image-policy" {
  activate_on_production = false
  contract_id            = "12345"
  policy_id              = "my-image-policy-1"
  policyset_id           = akamai_imaging_policy_set.my-policy-set.id
  json = data.akamai_imaging_policy_image.my-image-policy-definition.json
}
Changes to Outputs:
  + my-image-policy = {
      + id     = "12abcd34ef5ghi6i78klmn9012op34qrstuv56wx7yz"
      + json   = jsonencode(
            {
              + breakpoints     = {
                  + widths = [
                      + 280,
                      + 1080,
                    ]
                }
              + hosts           = [
                  + "www.example-1.com",
                  + "www.example-2.com",
                ]
              + output          = {
                  + adaptiveQuality   = 50
                  + perceptualQuality = "mediumHigh"
                }
              + transformations = [
                  + {
                      + gravity          = "Center"
                      + height           = 8
                      + regionOfInterest = {
                          + anchor = {
                              + x = 4
                              + y = 5
                            }
                          + height = 9
                          + width  = 8
                        }
                      + style            = "fill"
                      + transformation   = "RegionOfInterestCrop"
                      + width            = 7
                    },
                  + {
                      + gravity                = "Center"
                      + gravityPriority        = "horizontal"
                      + image                  = {
                          + fill       = "#000000"
                          + size       = 72
                          + stroke     = "#FFFFFF"
                          + strokeSize = 0
                          + text       = "test"
                          + type       = "Text"
                        }
                      + preserveMinorDimension = true
                      + transformation         = "Append"
                    },
                  + {
                      + fuzz           = 0.08
                      + padding        = 0
                      + transformation = "Trim"
                    },
                  + {
                      + default        = {
                          + aspect         = "fit"
                          + height         = {
                              + var = "ResizeDim"
                            }
                          + transformation = "Resize"
                          + type           = "normal"
                          + width          = {
                              + var = "ResizeDim"
                            }
                        }
                      + dimension      = "height"
                      + lessThan       = {
                          + allowExpansion = true
                          + gravity        = "Center"
                          + height         = {
                              + var = "ResizeDim"
                            }
                          + transformation = "Crop"
                          + width          = {
                              + var = "ResizeDim"
                            }
                          + xPosition      = 0
                          + yPosition      = 0
                        }
                      + transformation = "IfDimension"
                      + value          = {
                          + var = "MinDim"
                        }
                    },
                  + {
                      + allowedTransformations = [
                          + "Append",
                          + "Blur",
                          + "Crop",
                        ]
                      + query                  = {
                          + var = "imq"
                        }
                      + transformation         = "ImQuery"
                    },
                ]
              + variables       = [
                  + {
                      + defaultValue = "280"
                      + name         = "ResizeDim"
                      + type         = "number"
                    },
                  + {
                      + defaultValue = "1000"
                      + name         = "MinDim"
                      + type         = "number"
                    },
                  + {
                      + defaultValue = ""
                      + name         = "imq"
                      + type         = "string"
                    },
                ]
            }
        )
      + policy = [
          + {
              + breakpoints                     = [
                  + {
                      + widths = [
                          + 280,
                          + 1080,
                        ]
                    },
                ]
              + hosts                           = [
                  + "www.example-1.com",
                  + "www.example-2.com",
                ]
              + output                          = [
                  + {
                      + adaptive_quality           = "50"
                      + allow_pristine_on_downsize = ""
                      + allowed_formats            = []
                      + forced_formats             = []
                      + perceptual_quality         = "mediumHigh"
                      + perceptual_quality_floor   = ""
                      + perceptual_quality_var     = ""
                      + prefer_modern_formats      = ""
                      + quality                    = ""
                      + quality_var                = ""
                    },
                ]
              + post_breakpoint_transformations = []
              + rollout_duration                = ""
              + serve_stale_duration            = ""
              + transformations                 = [
                  + {
                      + append                  = []
                      + aspect_crop             = []
                      + background_color        = []
                      + blur                    = []
                      + chroma_key              = []
                      + composite               = []
                      + compound                = []
                      + contrast                = []
                      + crop                    = []
                      + face_crop               = []
                      + feature_crop            = []
                      + fit_and_fill            = []
                      + goop                    = []
                      + grayscale               = []
                      + hsl                     = []
                      + hsv                     = []
                      + if_dimension            = []
                      + if_orientation          = []
                      + im_query                = []
                      + max_colors              = []
                      + mirror                  = []
                      + mono_hue                = []
                      + opacity                 = []
                      + region_of_interest_crop = [
                          + {
                              + gravity            = "Center"
                              + gravity_var        = ""
                              + height             = "8"
                              + height_var         = ""
                              + region_of_interest = [
                                  + {
                                      + circle_shape    = []
                                      + point_shape     = []
                                      + polygon_shape   = []
                                      + rectangle_shape = [
                                          + {
                                              + anchor     = [
                                                  + {
                                                      + x     = "4"
                                                      + x_var = ""
                                                      + y     = "5"
                                                      + y_var = ""
                                                    },
                                                ]
                                              + height     = "9"
                                              + height_var = ""
                                              + width      = "8"
                                              + width_var  = ""
                                            },
                                        ]
                                      + union_shape     = []
                                    },
                                ]
                              + style              = "fill"
                              + style_var          = ""
                              + width              = "7"
                              + width_var          = ""
                            },
                        ]
                      + relative_crop           = []
                      + remove_color            = []
                      + resize                  = []
                      + rotate                  = []
                      + scale                   = []
                      + shear                   = []
                      + smart_crop              = []
                      + trim                    = []
                      + unsharp_mask            = []
                    },
                  + {
                      + append                  = [
                          + {
                              + gravity                      = "Center"
                              + gravity_priority             = "horizontal"
                              + gravity_priority_var         = ""
                              + gravity_var                  = ""
                              + image                        = [
                                  + {
                                      + box_image    = []
                                      + circle_image = []
                                      + text_image   = [
                                          + {
                                              + fill            = "#000000"
                                              + fill_var        = ""
                                              + size            = "72"
                                              + size_var        = ""
                                              + stroke          = "#FFFFFF"
                                              + stroke_size     = "0"
                                              + stroke_size_var = ""
                                              + stroke_var      = ""
                                              + text            = "test"
                                              + text_var        = ""
                                              + transformation  = []
                                              + typeface        = ""
                                              + typeface_var    = ""
                                            },
                                        ]
                                      + url_image    = []
                                    },
                                ]
                              + preserve_minor_dimension     = "true"
                              + preserve_minor_dimension_var = ""
                            },
                        ]
                      + aspect_crop             = []
                      + background_color        = []
                      + blur                    = []
                      + chroma_key              = []
                      + composite               = []
                      + compound                = []
                      + contrast                = []
                      + crop                    = []
                      + face_crop               = []
                      + feature_crop            = []
                      + fit_and_fill            = []
                      + goop                    = []
                      + grayscale               = []
                      + hsl                     = []
                      + hsv                     = []
                      + if_dimension            = []
                      + if_orientation          = []
                      + im_query                = []
                      + max_colors              = []
                      + mirror                  = []
                      + mono_hue                = []
                      + opacity                 = []
                      + region_of_interest_crop = []
                      + relative_crop           = []
                      + remove_color            = []
                      + resize                  = []
                      + rotate                  = []
                      + scale                   = []
                      + shear                   = []
                      + smart_crop              = []
                      + trim                    = []
                      + unsharp_mask            = []
                    },
                  + {
                      + append                  = []
                      + aspect_crop             = []
                      + background_color        = []
                      + blur                    = []
                      + chroma_key              = []
                      + composite               = []
                      + compound                = []
                      + contrast                = []
                      + crop                    = []
                      + face_crop               = []
                      + feature_crop            = []
                      + fit_and_fill            = []
                      + goop                    = []
                      + grayscale               = []
                      + hsl                     = []
                      + hsv                     = []
                      + if_dimension            = []
                      + if_orientation          = []
                      + im_query                = []
                      + max_colors              = []
                      + mirror                  = []
                      + mono_hue                = []
                      + opacity                 = []
                      + region_of_interest_crop = []
                      + relative_crop           = []
                      + remove_color            = []
                      + resize                  = []
                      + rotate                  = []
                      + scale                   = []
                      + shear                   = []
                      + smart_crop              = []
                      + trim                    = [
                          + {
                              + fuzz        = "0.08"
                              + fuzz_var    = ""
                              + padding     = "0"
                              + padding_var = ""
                            },
                        ]
                      + unsharp_mask            = []
                    },
                  + {
                      + append                  = []
                      + aspect_crop             = []
                      + background_color        = []
                      + blur                    = []
                      + chroma_key              = []
                      + composite               = []
                      + compound                = []
                      + contrast                = []
                      + crop                    = []
                      + face_crop               = []
                      + feature_crop            = []
                      + fit_and_fill            = []
                      + goop                    = []
                      + grayscale               = []
                      + hsl                     = []
                      + hsv                     = []
                      + if_dimension            = [
                          + {
                              + default       = [
                                  + {
                                      + append                  = []
                                      + aspect_crop             = []
                                      + background_color        = []
                                      + blur                    = []
                                      + chroma_key              = []
                                      + composite               = []
                                      + compound                = []
                                      + contrast                = []
                                      + crop                    = []
                                      + face_crop               = []
                                      + feature_crop            = []
                                      + fit_and_fill            = []
                                      + goop                    = []
                                      + grayscale               = []
                                      + hsl                     = []
                                      + hsv                     = []
                                      + if_dimension            = []
                                      + if_orientation          = []
                                      + im_query                = []
                                      + max_colors              = []
                                      + mirror                  = []
                                      + mono_hue                = []
                                      + opacity                 = []
                                      + region_of_interest_crop = []
                                      + relative_crop           = []
                                      + remove_color            = []
                                      + resize                  = [
                                          + {
                                              + aspect     = "fit"
                                              + aspect_var = ""
                                              + height     = ""
                                              + height_var = "ResizeDim"
                                              + type       = "normal"
                                              + type_var   = ""
                                              + width      = ""
                                              + width_var  = "ResizeDim"
                                            },
                                        ]
                                      + rotate                  = []
                                      + scale                   = []
                                      + shear                   = []
                                      + smart_crop              = []
                                      + trim                    = []
                                      + unsharp_mask            = []
                                    },
                                ]
                              + dimension     = "height"
                              + dimension_var = ""
                              + equal         = []
                              + greater_than  = []
                              + less_than     = [
                                  + {
                                      + append                  = []
                                      + aspect_crop             = []
                                      + background_color        = []
                                      + blur                    = []
                                      + chroma_key              = []
                                      + composite               = []
                                      + compound                = []
                                      + contrast                = []
                                      + crop                    = [
                                          + {
                                              + allow_expansion     = "true"
                                              + allow_expansion_var = ""
                                              + gravity             = "Center"
                                              + gravity_var         = ""
                                              + height              = ""
                                              + height_var          = "ResizeDim"
                                              + width               = ""
                                              + width_var           = "ResizeDim"
                                              + x_position          = "0"
                                              + x_position_var      = ""
                                              + y_position          = "0"
                                              + y_position_var      = ""
                                            },
                                        ]
                                      + face_crop               = []
                                      + feature_crop            = []
                                      + fit_and_fill            = []
                                      + goop                    = []
                                      + grayscale               = []
                                      + hsl                     = []
                                      + hsv                     = []
                                      + if_dimension            = []
                                      + if_orientation          = []
                                      + im_query                = []
                                      + max_colors              = []
                                      + mirror                  = []
                                      + mono_hue                = []
                                      + opacity                 = []
                                      + region_of_interest_crop = []
                                      + relative_crop           = []
                                      + remove_color            = []
                                      + resize                  = []
                                      + rotate                  = []
                                      + scale                   = []
                                      + shear                   = []
                                      + smart_crop              = []
                                      + trim                    = []
                                      + unsharp_mask            = []
                                    },
                                ]
                              + value         = ""
                              + value_var     = "MinDim"
                            },
                        ]
                      + if_orientation          = []
                      + im_query                = []
                      + max_colors              = []
                      + mirror                  = []
                      + mono_hue                = []
                      + opacity                 = []
                      + region_of_interest_crop = []
                      + relative_crop           = []
                      + remove_color            = []
                      + resize                  = []
                      + rotate                  = []
                      + scale                   = []
                      + shear                   = []
                      + smart_crop              = []
                      + trim                    = []
                      + unsharp_mask            = []
                    },
                  + {
                      + append                  = []
                      + aspect_crop             = []
                      + background_color        = []
                      + blur                    = []
                      + chroma_key              = []
                      + composite               = []
                      + compound                = []
                      + contrast                = []
                      + crop                    = []
                      + face_crop               = []
                      + feature_crop            = []
                      + fit_and_fill            = []
                      + goop                    = []
                      + grayscale               = []
                      + hsl                     = []
                      + hsv                     = []
                      + if_dimension            = []
                      + if_orientation          = []
                      + im_query                = [
                          + {
                              + allowed_transformations = [
                                  + "Append",
                                  + "Blur",
                                  + "Crop",
                                ]
                              + query_var               = "imq"
                            },
                        ]
                      + max_colors              = []
                      + mirror                  = []
                      + mono_hue                = []
                      + opacity                 = []
                      + region_of_interest_crop = []
                      + relative_crop           = []
                      + remove_color            = []
                      + resize                  = []
                      + rotate                  = []
                      + scale                   = []
                      + shear                   = []
                      + smart_crop              = []
                      + trim                    = []
                      + unsharp_mask            = []
                    },
                ]
              + variables                       = [
                  + {
                      + default_value = "280"
                      + enum_options  = []
                      + name          = "ResizeDim"
                      + postfix       = ""
                      + prefix        = ""
                      + type          = "number"
                    },
                  + {
                      + default_value = "1000"
                      + enum_options  = []
                      + name          = "MinDim"
                      + postfix       = ""
                      + prefix        = ""
                      + type          = "number"
                    },
                  + {
                      + default_value = ""
                      + enum_options  = []
                      + name          = "imq"
                      + postfix       = ""
                      + prefix        = ""
                      + type          = "string"
                    },
                ]
            },
        ]
    }

Arguments

Pass the required policy argument in the body of the declaration to specify settings in it for an image policy.

Argument Required Description
breakpoints The list of breakpoint widths in pixels used to create derivative images.
hosts The hosts allowed for image URLs within transformations or variables.
output The output quality and formats that are created for each resized image. If unspecified, image formats are created to support all browsers at the default quality level (85) including formats, like WEBP, JPEG2000, and JPEG-XR for specific browsers. Includes:
  • adaptive_quality. The quality value applied to an image when Image and Video Manager detects a slow connection (RTT > 300 ms). This value (1-100) overrides the derivative quality value.

    Specifying a lower value can reduce load times for users with slow connections without impacting the quality of images for users with standard connections.
  • perceptual_quality. The perceptual quality to use when comparing resulting images. Perceptual quality tunes each image format's quality parameter dynamically based on the human-perceived quality of the output image. The visual quality of derivative videos after they have been compressed to maximize byte savings. You can select one of five perceptual quality values: high, mediumHigh, medium, mediumLow, or low.

    high results in the highest visual quality with the least byte savings, while low results in lower visual quality with the greatest byte savings. You can set either perceptual_quality or quality, but not both.
  • perceptual_quality_var. Use this argument instead of perceptual_quality if setting a variable.
  • perceptual_quality_floor. Applies only when perceptual_quality is set. The minimum image quality to respect when perceptual quality is set. Image quality will not be reduced below this value even if it is determined that a further compressed image would be acceptably visually similar. Set a value between 1-100.
  • quality. The specified quality of the output images expressed as a value from 1-100. You can set either perceptual_quality or quality, but not both. If neither is set, quality is the default.
  • quality_var. Use this argument instead of quality if setting a variable.
  • allow_pristine_on_downsize. When set to true, this allows a pristine image to be wider than the requested breakpoint as a derivative image if it has the fewest bytes. This has no effect when using transformations.
  • prefer_modern_formats. When set to true, the preference for derivative image formats is for modern formats, like WebP and Avif, instead of the format that results in the fewest bytes.
  • allowed_formats. The graphics file formats allowed for browser-specific results.
  • forced_formats. The forced extra formats for the imFormat query parameter, which requests a specific browser type. By default, Image and Video Manager detects the browser and returns the appropriate image.
post_breakpoint_transformations The set of post-processing transformations applied to the image after image and quality settings have been applied. This is a subset of the complete list of transformations and includes:
  • background_color
  • blur
  • chroma_key
  • composite
  • compound
  • contrast
  • goop
  • grayscale
  • hsl
  • hsv
  • if_dimension
  • if_orientation
  • max_colors
  • mirror
  • mono_hue
  • opacity
  • remove_color
  • unsharp_mask
For information about these transformations and their supporting arguments, see Transform images.
rollout_duration The amount of time in seconds that it takes for the policy to roll out. During the rollout, the proportion of images with the new policy applied continually increases until cached videos associated with the previous version of the policy are no longer being served. The default is 3600 seconds.
transformations The set of image transformations applied to the original image. If unspecified, no operations are performed. For information about available transformations and their supporting arguments, see Transform images.
serve_stale_duration The amount of time in seconds that the policy serves stale images. If possible, during the serve stale period, real-time images attempt to use the offline image from the previous policy version.
variables The variables available for the policy. You can reference any variable declared here in transformations and output. You can also dynamically pass in these variable names and values as query parameters in the image's request URL. See Use variables for more information. Includes:
  • name. Required. The name of the variable which is also available as the query parameter name to set the variable's value dynamically. Can be up to 50 alphanumeric characters.
  • type. Required. The type of value for the variable. Value is one of:
    • bool
    • number
    • url
    • color
    • gravity
    • placement
    • scaleDimension
    • grayscaleType
    • aspect
    • resizeType
    • dimension
    • perceptualQuality
    • string
    • focus
  • default_value. Required. The default value of the variable if no query parameter is provided. It needs to be one of the enum_options if any are provided.
  • enum_options. Limits the set of possible values for a variable.
    • id. Required. The ID for each enum value. Can be up to 50 alphanumeric characters.
    • value. Required. The value of the variable when the id is provided.
  • postfix. A postfix added to the value provided for the variable, or to the default value.
  • prefix. A prefix added to the value provided for the variable, or to the default value.

Attributes

Returned to you is the JSON-encoded image policy.