The /image/optimize Robot

Transloadit can resize, crop, and (auto-)rotate images, as well as watermark them or read & write meta-data.

The /image/optimize Robot reduces the size of images while maintaining the same visual quality.

Parameters

Name Type Default Description
progressive Boolean false Interlaces the image if set to true, which makes the result image load progressively in browsers. Instead of rendering the image from top to bottom, the browser will first show a low-res blurry version of the image which is then quickly replaced with the actual image as the data arrives. This greatly increases the user experience, but comes at a loss of about 10% of the file size reduction.
preserve_meta_data Boolean true Specifies if the image's meta data should be preserved during the optimization, or not. If it is not preserved, the file size is even further reduced. This option is mandatory if you set png_tool to "pngquant"
fix_breaking_images Boolean true If set to true this parameter tries to fix images that would otherwise make the underlying tool error out and thereby break your Assemblies. This can sometimes result in a larger file size, though.

Example use cases

Our /image/optimize Robot can be used in combination with other Robots, to create powerful workflows unique to your use case.
Here are a few example scenarios, and the required the Assembly Instructions to implement them.
You can also try demos of these examples right here, live on our website.

Only resize larger images when resizing files

{
  "steps": {
    "large-files": {
      "use": ":original",
      "robot": "/file/filter",
      "accepts": [
        [
          "${file.meta.width}",
          ">",
          "2048"
        ],
        [
          "${file.meta.height}",
          ">",
          "2048"
        ]
      ],
      "condition_type": "or"
    },
    "smaller-files": {
      "use": ":original",
      "robot": "/file/filter",
      "accepts": [
        [
          "${file.meta.width}",
          "<=",
          "2048"
        ],
        [
          "${file.meta.height}",
          "<=",
          "2048"
        ]
      ],
      "condition_type": "or"
    },
    "large-resized": {
      "use": "large-files",
      "robot": "/image/resize",
      "resize_strategy": "fit",
      "width": 2048,
      "height": 2048
    },
    "smaller-resized": {
      "use": "smaller-files",
      "robot": "/image/resize",
      "resize_strategy": "fit",
      "width": "${file.meta.width}",
      "height": "${file.meta.height}"
    },
    "optimized": {
      "use": [
        "smaller-resized",
        "large-resized"
      ],
      "robot": "/image/optimize"
    },
    "exported": {
      "use": [
        "optimized",
        ":original"
      ],
      "robot": "/s3/store",
      "key": "YOUR_AWS_KEY",
      "secret": "YOUR_AWS_SECRET",
      "bucket": "YOUR_S3_BUCKET"
    }
  }
}

Reduce image file sizes by up to 80% without quality loss

{
  "steps": {
    "optimized": {
      "use": ":original",
      "robot": "/image/optimize",
      "result": true
    }
  }
}

Related blog posts

Over the years we wrote the following posts about Our /image/optimize robot on our blog:

Did you know?

You can easily combine Robots to create powerful workflows, unique to your business.
This is the power of Transloadit.