Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
image / image-thumbnailBuilt by daveRuns on Liberas

PNG thumbnail

A PNG resized to width × height: decoded through image-decode-png, resized with the bilinear filter through image-resize, encoded through image-encode-png. An error from any of them (not a PNG, a size of 0, a result over the pixel limit) is the call's error. Verified through image-decode-png like the encoder.

Depends onimage-decode-pngimage-encode-pngimage-resize

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init image-thumbnail --lang rust
cd image-thumbnail && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)43 lines›
image-thumbnail.wit
package root:component;

world root {
  import liberas:image/types@0.1.0;
  import image-decode-png: liberas:image/decode@0.1.0;
  import image-resize: liberas:image/resize@0.1.0;
  import image-encode-png: liberas:image/encode@0.1.0;

  export liberas:image/thumbnail@0.1.0;
}
package liberas:image@0.1.0 {
  interface types {
    record image {
      width: u32,
      height: u32,
      pixels: list<u8>,
    }
  }
  interface decode {
    use types.{image};

    decode: func(data: list<u8>) -> result<image, string>;
  }
  interface resize {
    use types.{image};

    enum filter {
      nearest,
      bilinear,
    }

    resize: func(input: image, width: u32, height: u32, filter: filter) -> result<image, string>;
  }
  interface encode {
    use types.{image};

    encode: func(input: image) -> result<list<u8>, string>;
  }
  interface thumbnail {
    thumbnail: func(data: list<u8>, width: u32, height: u32) -> result<list<u8>, string>;
  }
}
Current implementation: a compositionliberas-compose/1›
image-thumbnail.composition.json
{
  "functions": {
    "thumbnail": {
      "steps": [
        {
          "let": "image",
          "args": {
            "data": "$data"
          },
          "call": "image-decode-png.decode"
        },
        {
          "let": "small",
          "args": {
            "input": "$image",
            "width": "$width",
            "filter": "bilinear",
            "height": "$height"
          },
          "call": "image-resize.resize"
        },
        {
          "let": "png",
          "args": {
            "input": "$small"
          },
          "call": "image-encode-png.encode"
        }
      ],
      "return": "$png"
    }
  }
}
Test vectors15›
image-thumbnail.cases.json
[
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAAAIAAAAJCAAAAAA9GqI7AAAAHklEQVR42mNg4GdU5mdREmBRFmBR5mcUF2BR5ocgABV7AbAPb6LJAAAAAElFTkSuQmCC",
      "width": 1,
      "height": 1
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAAAYAAAADCAAAAACVaiEnAAAAHUlEQVR42mNk4BcQEBBgVOYX4BcQYFES4BcQEAAADBoBOGWBIsAAAAAASUVORK5CYII=",
      "width": 4,
      "height": 3
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAQAAAAnZu5uAAAAOUlEQVR42iXGMRGAMBBFwZeZ6/9TQMHJwEiMxBNGMIKRULDVDsgWkdE7SHDV+Wd6VyO5fKSaHL4SPsiWB0Y6dA9ZAAAAAElFTkSuQmCC",
      "width": 8,
      "height": 8
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIBAMAAAA2IaO4AAAAMFBMVEXX1iKDyxEw1Bw0oC3PjCB8fRIqhSApayrjUyWWTxTCJB2BGA8/SBQeNic4FhUcBBUwrXteAAAAM0lEQVR42gEoANf/Af/sz/ME3e3e7wSa3+//BO287wID8fj4LgHuzO41BN7f788D/9XY1RhMGkZnc93RAAAAAElFTkSuQmCC",
      "width": 3,
      "height": 7
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR42mNgYGAAAAAEAAHI6uv5AAAAAElFTkSuQmCC",
      "width": 16,
      "height": 12
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAYCAIAAAAUMWhjAAAA0UlEQVR42tWVUWvCQBAGE2IZSihSpEgRkSJDKUWklEVE/P9/y6dSkZjkkpNauKfluDnm270ri6KQUip5EORRanmSqTzLTF5kLq+ykKWs5E3WorzLh3zKRrbyJd8SspO9HOQ4qaOqKWuqG62bASId4LVitO1sBth6qRyK4j4ysEexAWDvszoTztFFkUtRDJR2CTCGud5kDHn115MciYBBA7xrBjgu4R6K4j5eU1OKv4AMA9zkYGgXRS5FI1LxHND5b/ysZarJf/QnRyKgTUUkdO0JBptQo8XnbZgAAAAASUVORK5CYII=",
      "width": 2,
      "height": 2
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAAAcAAAAFCAIAAAAG+GGPAAAALElEQVR42mNkYGBQZWdUZWdWZWdVZWdXZedUZedm4TZl5mZn5GZnRkaUiwIAAW4EOsAGp5AAAAAASUVORK5CYII=",
      "width": 1,
      "height": 1
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAEEAIAAACZwb5UAAAAg0lEQVR42mNgAAO1rwLMDM2+rxTYGNlK7htwMnbOvuLAw8TDwGjOwJ7ar6EjwJUm5K+owJs2tUzMQCBdYi63g3D6bAamPAa+03KayQKCpxcGRCiInFEp9zUQP7N8npOD1FktBualDKIGa7VmCUgYGgT2K0gbbq5oMZAzMptf6aBotBMAMG4g5d3dq8MAAAAASUVORK5CYII=",
      "width": 4,
      "height": 3
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA9ElEQVR42r2SIU5DURRE78sUJs2kIYQQ0jRgmtkBT2HYAg7DAjB1GBaAqathARgchgVgcGyhpo4tYD6i/ycvj5ZWUMQV9+bcESeTIiLM1JgIcy9MhtmfmZqYgzAPwjwM82hsHs/NkzCHYY7CPH3tKaMRU4jo5k7EtNhDxL6Ir+r2KOK2p4woAq5FPFfg54rnexEPIqIMuBDxXoEfIs6r242IJ7d7F3AmYlGBLyauqtuliDcRsfxbBiQxNRU4EzHpoHbGIuYVt0OJ/kWi/0KitpGodRILNyslOrcS+VOi/03iTprobSR6k8TcNnGtxFw0kZub+A211FRQtBRYZAAAAABJRU5ErkJggg==",
      "width": 8,
      "height": 8
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAANklEQVR42k3IsREAIQwDwfMIRoHqcAlENELDXxefsuEWQLtuW7QnI0s3LmIRi5Elnjhv7FjfD7+vBXE37TepAAAAAElFTkSuQmCC",
      "width": 3,
      "height": 7
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAAAkAAAAHCAYAAADam2dgAAAAfUlEQVR42o3OsQ3CUBADUJ+cyEIWYgO62yCpmIKOKdIxBV2moGOKdExBlyk+BfrS168orrD0ZF8AQCpKikiNSAmpw5rykjoidcLgmcUKWKx3t/hoMgbPRINuFp8tsLi36GJx68Db4lTR2eKnA68Ur3UurCgdWC0uvwL+9/gXF+cVXtFZz/wAAAAASUVORK5CYII=",
      "width": 16,
      "height": 12
    }
  },
  {
    "args": {
      "data": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4pLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//wgALCAAIABABAREA/8QAFAABAAAAAAAAAAAAAAAAAAAABP/aAAgBAQAAAAE6P//EABcQAQEBAQAAAAAAAAAAAAAAAAECAxP/2gAIAQEAAQUCiczMHn//xAAaEAACAgMAAAAAAAAAAAAAAAAAAQIRAyJh/9oACAEBAAY/AnpIpYlb6f/EABcQAQEBAQAAAAAAAAAAAAAAAAERAEH/2gAIAQEAAT8hRBmQEDAAidrf/9oACAEBAAAAEH//xAAaEAEAAgMBAAAAAAAAAAAAAAABESEAMbFB/9oACAEBAAE/EEoWABWty8wSSAWEFtAd9z//2Q==",
      "width": 4,
      "height": 4
    }
  },
  {
    "args": {
      "data": "bm90IGFuIGltYWdlIGF0IGFsbA==",
      "width": 4,
      "height": 4
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAAAIAAAAJCAAAAAA9GqI7AAAAHklEQVR42mNg4GdU5mdREmBRFmBR5mcUF2BR5ocgABV7AbAPb6LJAAAAAElFTkSuQmCC",
      "width": 0,
      "height": 4
    }
  },
  {
    "args": {
      "data": "iVBORw0KGgoAAAANSUhEUgAAAAIAAAAJCAAAAAA9GqI7AAAAHklEQVR42mNg4GdU5mdREmBRFmBR5mcUF2BR5ocgABV7AbAPb6LJAAAAAElFTkSuQmCC",
      "width": 100000,
      "height": 100000
    }
  }
]
Versions (units)1›
  1. v1by dave1afd42561fstable 1.1.0latestconfirmed10/26/2026
Verification9›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 15 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • The reference imports image-decode-png, image-resize, image-encode-png. Yours may import those, other specs, or none: an import is named after its spec, and the platform links that spec's current component. A verified implementation of a spec is interchangeable with any other.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • Outputs are compared after image-decode-png's reference maps them: any output that canonicalizes to the reference's passes (an encoder is verified through its decoder).
  • A remote call may execute up to 10,000,000,000 instructions.
  • Already built: a component that passes and uses at most 0.9× the current one's fuel on the same cases replaces it, and earns the spec's shares in proportion to the saving.
  • Found an input where the current component disagrees with the spec? Submit it as a case (API or `liberas case`): it joins the vectors for good and earns 10% of the spec's shares. A component that then passes replaces the broken one for 25%.