<br />

Function for decode_bmp, decode_gif, decode_jpeg, decode_jxl, decode_webp, and decode_png.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.raw_ops.DecodeImage`](https://www.tensorflow.org/api_docs/python/tf/raw_ops/DecodeImage)

<br />

    tf.raw_ops.DecodeImage(
        contents,
        channels=0,
        dtype=https://www.tensorflow.org/api_docs/python/tf/dtypes#uint8,
        expand_animations=True,
        name=None
    )

Detects whether an image is a BMP, GIF, JPEG, JPEG XL, WebP, or PNG, and
performs the appropriate operation to convert the input bytes string into a
Tensor of type dtype.

> [!NOTE]
> **Note:** decode_gif and decode_webp return a 4-D array \[num_frames, height, width, 3\], as opposed to decode_bmp, decode_jpeg, and decode_png, which always return 3-D arrays \[height, width, num_channels\]. Make sure to take this into account when constructing your graph if you are intermixing animated files with BMP, JPEG, and/or PNG files. Alternately, set the expand_animations argument of this function to False, in which case the op will return 3-dimensional tensors and will truncate animations to the first frame.

> [!NOTE]
> **Note:** If the first frame of an animated GIF does not occupy the entire canvas (maximum frame width x maximum frame height), then it fills the unoccupied areas (in the first frame) with zeros (black). For frames after the first frame that does not occupy the entire canvas, it uses the previous frame to fill the unoccupied areas.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `contents` | A `Tensor` of type `string`. 0-D. The encoded image bytes. |
| `channels` | An optional `int`. Defaults to `0`. Number of color channels for the decoded image. |
| `dtype` | An optional [`tf.DType`](https://www.tensorflow.org/api_docs/python/tf/dtypes/DType) from: `tf.uint8, tf.uint16, tf.float32`. Defaults to [`tf.uint8`](https://www.tensorflow.org/api_docs/python/tf#uint8). The desired DType of the returned Tensor. |
| `expand_animations` | An optional `bool`. Defaults to `True`. Controls the output shape of the returned op. If True, the returned op will produce a 3-D tensor for PNG, JPEG, JPEG XL, and BMP files; and a 4-D tensor for all GIFs and WebP images, whether animated or not. If, False, the returned op will produce a 3-D tensor for all file types and will truncate animated images to the first frame. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` of type `dtype`. ||

<br />