{"id":13439733,"url":"https://github.com/image-rs/image","last_synced_at":"2026-04-02T01:36:27.387Z","repository":{"id":17381098,"uuid":"20153092","full_name":"image-rs/image","owner":"image-rs","description":"Encoding and decoding images in Rust","archived":false,"fork":false,"pushed_at":"2025-04-26T05:53:39.000Z","size":36978,"stargazers_count":5260,"open_issues_count":244,"forks_count":642,"subscribers_count":82,"default_branch":"main","last_synced_at":"2025-05-05T20:51:35.338Z","etag":null,"topics":["decoding-images","pixel","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/image-rs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-05-25T11:39:07.000Z","updated_at":"2025-05-05T12:41:51.000Z","dependencies_parsed_at":"2024-01-13T20:50:18.545Z","dependency_job_id":"f866ec5d-e0bf-48b4-a1ff-01ee2bd46027","html_url":"https://github.com/image-rs/image","commit_stats":{"total_commits":2358,"total_committers":335,"mean_commits":7.038805970149253,"dds":0.8282442748091603,"last_synced_commit":"e0c250fa0a0ff458bef96a795ecf108494a160cf"},"previous_names":["pistondevelopers/image"],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/image-rs%2Fimage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/image-rs%2Fimage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/image-rs%2Fimage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/image-rs%2Fimage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/image-rs","download_url":"https://codeload.github.com/image-rs/image/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253181530,"owners_count":21867010,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["decoding-images","pixel","rust"],"created_at":"2024-07-31T03:01:16.614Z","updated_at":"2026-04-02T01:36:27.380Z","avatar_url":"https://github.com/image-rs.png","language":"Rust","readme":"# Image\n[![crates.io](https://img.shields.io/crates/v/image.svg)](https://crates.io/crates/image)\n[![Documentation](https://docs.rs/image/badge.svg)](https://docs.rs/image)\n[![Build Status](https://github.com/image-rs/image/workflows/Rust%20CI/badge.svg)](https://github.com/image-rs/image/actions)\n[![Gitter](https://badges.gitter.im/image-rs/image.svg)](https://gitter.im/image-rs/image?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\nMaintainers: [@197g](https://github.com/197g), [@fintelia](https://github.com/fintelia)\n\n[How to contribute](https://github.com/image-rs/organization/blob/master/CONTRIBUTING.md)\n\n## An Image Processing Library\n\nThis crate provides basic image processing functions and methods for converting to and from various image formats.\n\nAll image processing functions provided operate on types that implement the `GenericImageView` and `GenericImage` traits and return an `ImageBuffer`.\n\n## High level API\n\nLoad images using [`ImageReader`]:\n\n```rust,ignore\nuse std::io::Cursor;\nuse image::ImageReader;\n\nlet img = ImageReader::open(\"myimage.png\")?.decode()?;\nlet img2 = ImageReader::new(Cursor::new(bytes)).with_guessed_format()?.decode()?;\n```\n\nAnd save them using [`save`] or [`write_to`] methods:\n\n```rust,ignore\nimg.save(\"empty.jpg\")?;\n\nlet mut bytes: Vec\u003cu8\u003e = Vec::new();\nimg2.write_to(\u0026mut Cursor::new(\u0026mut bytes), image::ImageFormat::Png)?;\n```\n\n## Supported Image Formats\n\nWith default features enabled, `image` provides implementations of [many common\nimage format encoders and decoders.](https://docs.rs/image/latest/image/codecs/index.html#supported-formats)\n\nDecoding support for additional image formats is provided by\n[`image-extras`](https://github.com/image-rs/image-extras), and the same plugin\ninterface lets third-party crates act as format implementations for `image`. If\nyou need to handle some other image format, check crates.io for crates that\nimplement it.\n\n## Feature Flags\n\n| Feature           | Description\n| ----------------- | -----------\n| `default-formats` | **Default**\u003cbr\u003eFormat support for common image formats: AVIF, BMP, EXR, FF, GIF, HDR, ICO, JPEG, PNG, PNM, QOI, TGA, TIFF, and WebP\n| `rayon`           | **Default**\u003cbr\u003eEnables multi-threading with rayon context in some dependencies\n| `nasm`            | Enables the build-time use of `nasm` for `ravif`, requires `nasm` installed\n| `color_quant`     | Includes `color_quant` as an implementation of `imageops::ColorMap`\n| `avif-native`     | Enables non-Rust dependencies of `avif` (`mp4parse` and `dav1d`)\n| `serde`           | Enables `serde` integration for various structs and options\n\nNote: When using `image` in a library you intend to publish, it is recommended to set `default-features = false` and then explicitly enable format features that are absolutely necessary. This ensures a smaller dependency tree and faster iteration time. The default feature configuration would also enable multithreading which may cause unexpected behavior when running for inherently single-threaded environments such as `wasm` targets.\n\n## Image Types\n\nThis crate provides a number of different types for representing images.\nIndividual pixels within images are indexed with (0,0) at the top left corner.\n\n### [`ImageBuffer`](https://docs.rs/image/*/image/struct.ImageBuffer.html)\nAn image parameterised by its Pixel type, represented by a width and height and\na vector of pixels. It provides direct access to its pixels and implements the\n`GenericImageView` and `GenericImage` traits.\n\n### [`DynamicImage`](https://docs.rs/image/*/image/enum.DynamicImage.html)\nA `DynamicImage` is an enumeration over all supported `ImageBuffer\u003cP\u003e` types.\nIts exact image type is determined at runtime. It is the type returned when\nopening an image. For convenience `DynamicImage` reimplements all image\nprocessing functions.\n\n### The [`GenericImageView`](https://docs.rs/image/*/image/trait.GenericImageView.html) and [`GenericImage`](https://docs.rs/image/*/image/trait.GenericImage.html) Traits\n\nTraits that provide methods for inspecting (`GenericImageView`) and manipulating (`GenericImage`) images, parameterised over the image's pixel type.\n\n### [`SubImage`](https://docs.rs/image/*/image/struct.SubImage.html)\nA view into another image, delimited by the coordinates of a rectangle.\nThe coordinates given set the position of the top left corner of the rectangle.\nThis is used to perform image processing functions on a subregion of an image.\n\n\n## The [`ImageDecoder`](https://docs.rs/image/*/image/trait.ImageDecoder.html) Trait\n\nAll image format decoders implement the `ImageDecoder` trait which provide\nbasic methods for getting image metadata and decoding images.\n\nThe most important methods for decoders are...\n+ **dimensions**: Return a tuple containing the width and height of the image.\n+ **color_type**: Return the color type of the image data produced by this decoder.\n+ **read_image**: Decode the entire image into a slice of bytes.\n\n## Pixels\n\n`image` provides the following pixel types:\n+ **Rgb**: RGB pixel\n+ **Rgba**: RGB with alpha (RGBA pixel)\n+ **Luma**: Grayscale pixel\n+ **LumaA**: Grayscale with alpha\n\nAll pixels are parameterised by their component type.\n\n## Image Processing Functions\n\nThese are the functions defined in the [`imageops`](https://docs.rs/image/latest/image/imageops/index.html) module. All functions operate on types that implement the [`GenericImage`](https://docs.rs/image/latest/image/trait.GenericImage.html) trait.\nNote that some of the functions are very slow in debug mode. Make sure to use release mode if you experience any performance issues.\n\n+ [**blur**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.blur): Performs a Gaussian blur on the supplied image.\n+ [**brighten**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.brighten): Brighten the supplied image.\n+ [**huerotate**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.huerotate): Hue rotate the supplied image by degrees.\n+ [**contrast**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.adjust_contrast): Adjust the contrast of the supplied image.\n+ [**crop**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.crop): Return a mutable view into an image.\n+ [**filter3x3**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.filter3x3): Perform a 3x3 box filter on the supplied image.\n+ [**flip_horizontal**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.fliph): Flip an image horizontally.\n+ [**flip_vertical**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.flipv): Flip an image vertically.\n+ [**grayscale**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.grayscale): Convert the supplied image to grayscale.\n+ [**invert**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.invert): Invert each pixel within the supplied image This function operates in place.\n+ [**resize**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.resize): Resize the supplied image to the specified dimensions.\n+ [**rotate180**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.rotate180): Rotate an image 180 degrees clockwise.\n+ [**rotate270**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.rotate270): Rotate an image 270 degrees clockwise.\n+ [**rotate90**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.rotate90): Rotate an image 90 degrees clockwise.\n+ [**unsharpen**](https://docs.rs/image/latest/image/enum.DynamicImage.html#method.unsharpen): Performs an unsharpen mask on the supplied image.\n\nFor more options, see the [`imageproc`](https://crates.io/crates/imageproc) crate.\n\n## Examples\n### Opening and Saving Images\n\n`image` provides the [`open`](https://docs.rs/image/latest/image/fn.open.html) function for opening images from a path.  The image\nformat is determined from the path's file extension. An `io` module provides a\nreader which offer some more control.\n\n```rust,no_run\nuse image::GenericImageView;\n\n// Use the open function to load an image from a Path.\n// `open` returns a `DynamicImage` on success.\nlet img = image::open(\"tests/images/jpg/progressive/cat.jpg\").unwrap();\n\n// The dimensions method returns the images width and height.\nprintln!(\"dimensions {:?}\", img.dimensions());\n\n// The color method returns the image's `ColorType`.\nprintln!(\"{:?}\", img.color());\n\n// Write the contents of this image to the Writer in PNG format.\nimg.save(\"test.png\").unwrap();\n```\n\n### Generating Fractals\n\n```rust,no_run\n//! An example of generating julia fractals.\nlet imgx = 800;\nlet imgy = 800;\n\nlet scalex = 3.0 / imgx as f32;\nlet scaley = 3.0 / imgy as f32;\n\n// Create a new ImgBuf with width: imgx and height: imgy\nlet mut imgbuf = image::ImageBuffer::new(imgx, imgy);\n\n// Iterate over the coordinates and pixels of the image\nfor (x, y, pixel) in imgbuf.enumerate_pixels_mut() {\n    let r = (0.3 * x as f32) as u8;\n    let b = (0.3 * y as f32) as u8;\n    *pixel = image::Rgb([r, 0, b]);\n}\n\n// A redundant loop to demonstrate reading image data\nfor x in 0..imgx {\n    for y in 0..imgy {\n        let cx = y as f32 * scalex - 1.5;\n        let cy = x as f32 * scaley - 1.5;\n\n        let c = num_complex::Complex::new(-0.4, 0.6);\n        let mut z = num_complex::Complex::new(cx, cy);\n\n        let mut i = 0;\n        while i \u003c 255 \u0026\u0026 z.norm() \u003c= 2.0 {\n            z = z * z + c;\n            i += 1;\n        }\n\n        let pixel = imgbuf.get_pixel_mut(x, y);\n        let image::Rgb(data) = *pixel;\n        *pixel = image::Rgb([data[0], i as u8, data[2]]);\n    }\n}\n\n// Save the image as “fractal.png”, the format is deduced from the path\nimgbuf.save(\"fractal.png\").unwrap();\n```\n\nExample output:\n\n\u003cimg src=\"examples/fractal.png\" alt=\"A Julia Fractal, c: -0.4 + 0.6i\" width=\"500\" /\u003e\n\n### Writing raw buffers\nIf the high level interface is not needed because the image was obtained by other means, `image` provides the function [`save_buffer`](https://docs.rs/image/latest/image/fn.save_buffer.html) to save a buffer to a file.\n\n```rust,no_run\nlet buffer: \u0026[u8] = unimplemented!(); // Generate the image data\n\n// Save the buffer as \"image.png\"\nimage::save_buffer(\"image.png\", buffer, 800, 600, image::ExtendedColorType::Rgb8).unwrap()\n```\n","funding_links":[],"categories":["Libraries","Rust","Programming","库 Libraries","Repository","库","其他_机器视觉","Image and Video Processing","Rust Libraries","虚拟化"],"sub_categories":["Image processing","Rust 🦀","图像处理 Image processing","Image","图像处理","网络服务_其他","Who this is for","图形处理"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimage-rs%2Fimage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimage-rs%2Fimage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimage-rs%2Fimage/lists"}