Specify the image output encoding to use.
The encode
parameter is useful for creating compact representations of images, such as placeholders or thumbnails. It provides support for encoding images as Base64 or data URL strings, which can be stored in a database for future use as embedded or in-line placeholders within Web pages.
Values
Accepted values for this parameter are binary
, base64
, and dataurl
with binary
as default value.
Binary encode=binary
When encoding an image, the default encoding method is binary
. If this method is selected you can expect to receive a normal response that includes the binary representation of your image.
Base64 encode=base64
The base64
encoding method encodes binary data as Base64 characters in the request response. This results in the codification of the image as binary data in Base64 format.
For the following example, we are requesting a small image thumbnail of 32
pixels wide with width=32
, removing all image metadata using strip=all
, and encoding it as Base64 with encode=base64
:
https://play.imglab-cdn.net/bird.jpeg?width=32&strip=all&encode=base64
When using the parameter strip=all
, it is important to note that this will strip all image metadata from the output. This results in a smaller Base64 encoded response, as the elimination of metadata reduces the final size.
Resulting in the following Base64 string response:
/9j/4QC8RXhpZgAASUkqAAgAAAAGABIBAwABAAAAAQAAABoBBQABAAAAVgAAABsBBQABAAAAXgAAACgBAwABAAAAAgAAABMCAwABAAAAAQAAAGmHBAABAAAAZgAAAAAAAABIAAAAAQAAAEgAAAABAAAABgAAkAcABAAAADAyMTABkQcABAAAAAECAwAAoAcABAAAADAxMDABoAMAAQAAAP//AAACoAQAAQAAACAAAAADoAQAAQAAABgAAAAAAAAA/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgAGAAgAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8AmudXmAEflHaG+YL2p2lanHFqUwhZwJBgAjvUv2Py7QGdZVY9WC5z+IrDvprazuIptomVGy/GWVcckDjNcFGnJzUZysjzumi1N2fQrSFnvJhumlbJOagTSEF3+8uoI+6hjzVSW+86My21wskMo3IUYlRz781EdUjt8SXamTIwWFZYyCd4x6dSUpX1M1hZtEtxHAYyeoQlSD+GKlXTLu92q13eRxMPl3SlsfQtk0UVz1a000l1RopyV0OihfTYPsgWO6RHLbnYocHqPl755zir8V1aKCs1hcxoR94YmH6Yb9KKKjE4mcXFaakuXc//2Q==
In the previous example, we are not specifying an output format. Thus the default will be JPEG. Alternatively, you can use the format
parameter to generate Base64 representations for any other supported image format.
The dataurl
encoding method will generate a response using data URL scheme as defined by RFC 2397. This encoding method can be useful to embed small images directly inline as URLs.
https://play.imglab-cdn.net/bird.jpeg?width=32&strip=all&encode=dataurl
Resulting in the following data URL string response:
data:image/jpeg;base64,/9j/4QC8RXhpZgAASUkqAAgAAAAGABIBAwABAAAAAQAAABoBBQABAAAAVgAAABsBBQABAAAAXgAAACgBAwABAAAAAgAAABMCAwABAAAAAQAAAGmHBAABAAAAZgAAAAAAAABIAAAAAQAAAEgAAAABAAAABgAAkAcABAAAADA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QlSD+GKlXTLu92q13eRxMPl3SlsfQtk0UVz1a000l1RopyV0OihfTYPsgWO6RHLbnYocHqPl755zir8V1aKCs1hcxoR94YmH6Yb9KKKjE4mcXFaakuXc//2Q==
You can request any other image format supported by the format
parameter. In the following URL, we will get a data URL encoded response for a WebP image using format=webp
and encode=dataurl
:
https://play.imglab-cdn.net/bird.jpeg?width=32&strip=all&format=webp&encode=dataurl
Resulting in the following response:
data:image/webp;base64,UklGRhgCAABXRUJQVlA4WAoAAAAIAAAAHwAAFwAAVlA4IDgBAADwBgCdASogABgAPpE6mEgloyKhKA1QsBIJbACdMuN6f6rdGeCxs3ngHp2S1tQZcoyncN3yKzBYIK7Y6YhWyWEAAP7F3y/auLOTfT5v72xJtaj/io/i3CdIfRoI3eUMevqj6YVW2VLEZwFlyFo8v42mT6uUk8u0//JCgA4pxIMb64UVzCvMD9e+S9taFvVq42l2vg3zF17TLZH4a6zsF2RvuP12s5gWQvOndYfHgOAkxNvF2hpDR9wmpgRIyJSOQ2FDdNEcFXZNjt+466Pp/n4jSLEjYku8Sx5xdVOeWinHIC1pDxifRvMmYErTqOyLZtpwhTxMuC8kzkzy2xyE/ZlDk/vfkHfg2tnqqDZICh2w/D0jS3Sz0kliMr+PFEKqHqxUfFP2JZlH+MmFfZxyFCnQ5OHQ6wgAAABFWElGugAAAEV4aWYAAElJKgAIAAAABgASAQMAAQAAAAEAAAAaAQUAAQAAAFYAAAAbAQUAAQAAAF4AAAAoAQMAAQAAAAIAAAATAgMAAQAAAAEAAABphwQAAQAAAGYAAAAAAAAASAAAAAEAAABIAAAAAQAAAAYAAJAHAAQAAAAwMjEwAZEHAAQAAAABAgMAAKAHAAQAAAAwMTAwAaADAAEAAAD//wAAAqAEAAEAAAAgAAAAA6AEAAEAAAAYAAAAAAAAAA==