# Optimizing/Resizing images to a certain file size?

**URL:** https://community.transloadit.com/t/optimizing-resizing-images-to-a-certain-file-size/16016
**Category:** Transloadit
**Created:** [March 28, 2022, 2:16pm UTC](https://community.transloadit.com/t/optimizing-resizing-images-to-a-certain-file-size/16016 "2022-03-28T14:16:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![njtobk](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/njtobk/32/553_2.png) [@njtobk](https://community.transloadit.com/u/njtobk)
#### Post date: [March 28, 2022, 2:16pm UTC](https://community.transloadit.com/t/optimizing-resizing-images-to-a-certain-file-size/16016/1 "2022-03-28T14:16:17Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![WardenScotland](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/wardenscotland/32/323_2.png) [@WardenScotland](https://community.transloadit.com/u/WardenScotland)
#### Post date: [April 11, 2022, 8:49pm UTC](https://community.transloadit.com/t/optimizing-resizing-images-to-a-certain-file-size/16016/2 "2022-04-11T20:49:48Z")

</div>

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:

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