Optimizing/Resizing images to a certain file size?

Hello! New to Transloadit. Have started using the optimize and resize robots. Is there a way to specify a max size that the resulting image will have? For example, if I have a 5 mb file, I want to guarantee that after optimizing/resizing the file size will be no larger than 3 mb.

Thanks!

Hello, there’s no way to know the optimized file size result before your Assembly completes. However, you could discard results from your optimizing Step that surpass 3MB using the below Template Step:

{
  "steps": {
    "files_filtered": {
      "use": ":original",
      "robot": "/file/filter",
      "declines": [
        [
          "${file.size}",
          ">",
          "3145728"
        ]
      ],
      "error_on_decline": false,
      "result": true
    }
  }
}