[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-5655":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":24,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":29,"readmeContent":30,"aiSummary":31,"trendingCount":16,"starSnapshotCount":16,"syncStatus":19,"lastSyncTime":32,"discoverSource":33},5655,"image","image-rs\u002Fimage","image-rs","Encoding and decoding images in Rust","",null,"Rust",5786,702,79,147,0,14,51,2,76.64,"Apache License 2.0",false,"main",true,[26,27,28],"decoding-images","pixel","rust","2026-06-12 04:00:26","# Image\n[![crates.io](https:\u002F\u002Fimg.shields.io\u002Fcrates\u002Fv\u002Fimage.svg)](https:\u002F\u002Fcrates.io\u002Fcrates\u002Fimage)\n[![Documentation](https:\u002F\u002Fdocs.rs\u002Fimage\u002Fbadge.svg)](https:\u002F\u002Fdocs.rs\u002Fimage)\n[![Build Status](https:\u002F\u002Fgithub.com\u002Fimage-rs\u002Fimage\u002Fworkflows\u002FRust%20CI\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fimage-rs\u002Fimage\u002Factions)\n[![Gitter](https:\u002F\u002Fbadges.gitter.im\u002Fimage-rs\u002Fimage.svg)](https:\u002F\u002Fgitter.im\u002Fimage-rs\u002Fimage?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)\n\nMaintainers: [@197g](https:\u002F\u002Fgithub.com\u002F197g), [@fintelia](https:\u002F\u002Fgithub.com\u002Ffintelia)\n\n[How to contribute](https:\u002F\u002Fgithub.com\u002Fimage-rs\u002Forganization\u002Fblob\u002Fmaster\u002FCONTRIBUTING.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> = Vec::new();\nimg2.write_to(&mut Cursor::new(&mut 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:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fcodecs\u002Findex.html#supported-formats)\n\nDecoding support for additional image formats is provided by\n[`image-extras`](https:\u002F\u002Fgithub.com\u002Fimage-rs\u002Fimage-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>Format support for common image formats: AVIF, BMP, EXR, FF, GIF, HDR, ICO, JPEG, PNG, PNM, QOI, TGA, TIFF, and WebP\n| `rayon`           | **Default**\u003Cbr>Enables 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:\u002F\u002Fdocs.rs\u002Fimage\u002F*\u002Fimage\u002Fstruct.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:\u002F\u002Fdocs.rs\u002Fimage\u002F*\u002Fimage\u002Fenum.DynamicImage.html)\nA `DynamicImage` is an enumeration over all supported `ImageBuffer\u003CP>` 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:\u002F\u002Fdocs.rs\u002Fimage\u002F*\u002Fimage\u002Ftrait.GenericImageView.html) and [`GenericImage`](https:\u002F\u002Fdocs.rs\u002Fimage\u002F*\u002Fimage\u002Ftrait.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:\u002F\u002Fdocs.rs\u002Fimage\u002F*\u002Fimage\u002Fstruct.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:\u002F\u002Fdocs.rs\u002Fimage\u002F*\u002Fimage\u002Ftrait.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:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fimageops\u002Findex.html) module. All functions operate on types that implement the [`GenericImage`](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Ftrait.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:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.blur): Performs a Gaussian blur on the supplied image.\n+ [**brighten**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.brighten): Brighten the supplied image.\n+ [**huerotate**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.huerotate): Hue rotate the supplied image by degrees.\n+ [**contrast**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.adjust_contrast): Adjust the contrast of the supplied image.\n+ [**crop**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.crop): Return a mutable view into an image.\n+ [**filter3x3**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.filter3x3): Perform a 3x3 box filter on the supplied image.\n+ [**flip_horizontal**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.fliph): Flip an image horizontally.\n+ [**flip_vertical**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.flipv): Flip an image vertically.\n+ [**grayscale**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.grayscale): Convert the supplied image to grayscale.\n+ [**invert**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.invert): Invert each pixel within the supplied image This function operates in place.\n+ [**resize**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.resize): Resize the supplied image to the specified dimensions.\n+ [**rotate180**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.rotate180): Rotate an image 180 degrees clockwise.\n+ [**rotate270**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.rotate270): Rotate an image 270 degrees clockwise.\n+ [**rotate90**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.rotate90): Rotate an image 90 degrees clockwise.\n+ [**unsharpen**](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Fenum.DynamicImage.html#method.unsharpen): Performs an unsharpen mask on the supplied image.\n\nFor more options, see the [`imageproc`](https:\u002F\u002Fcrates.io\u002Fcrates\u002Fimageproc) crate.\n\n## Examples\n### Opening and Saving Images\n\n`image` provides the [`open`](https:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Ffn.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\u002F\u002F Use the open function to load an image from a Path.\n\u002F\u002F `open` returns a `DynamicImage` on success.\nlet img = image::open(\"tests\u002Fimages\u002Fjpg\u002Fprogressive\u002Fcat.jpg\").unwrap();\n\n\u002F\u002F The dimensions method returns the images width and height.\nprintln!(\"dimensions {:?}\", img.dimensions());\n\n\u002F\u002F The color method returns the image's `ColorType`.\nprintln!(\"{:?}\", img.color());\n\n\u002F\u002F 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\u002F\u002F! An example of generating julia fractals.\nlet imgx = 800;\nlet imgy = 800;\n\nlet scalex = 3.0 \u002F imgx as f32;\nlet scaley = 3.0 \u002F imgy as f32;\n\n\u002F\u002F Create a new ImgBuf with width: imgx and height: imgy\nlet mut imgbuf = image::ImageBuffer::new(imgx, imgy);\n\n\u002F\u002F 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\u002F\u002F 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 && 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\u002F\u002F 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\u002Ffractal.png\" alt=\"A Julia Fractal, c: -0.4 + 0.6i\" width=\"500\" \u002F>\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:\u002F\u002Fdocs.rs\u002Fimage\u002Flatest\u002Fimage\u002Ffn.save_buffer.html) to save a buffer to a file.\n\n```rust,no_run\nlet buffer: &[u8] = unimplemented!(); \u002F\u002F Generate the image data\n\n\u002F\u002F Save the buffer as \"image.png\"\nimage::save_buffer(\"image.png\", buffer, 800, 600, image::ExtendedColorType::Rgb8).unwrap()\n```\n","image-rs\u002Fimage 是一个用 Rust 编写的图像处理库，支持多种图像格式的编码和解码。其核心功能包括基本的图像处理操作、不同格式之间的转换以及通过 `GenericImageView` 和 `GenericImage` 特性进行图像处理。该库支持常见的图像格式如 AVIF、BMP、GIF、JPEG、PNG 等，并且可以通过启用特定的功能标志来扩展支持更多格式或增强性能（例如多线程处理）。此外，它还提供了高级 API 以简化图像加载和保存过程。适用于需要在 Rust 项目中高效处理图像数据的各种场景，如图像编辑工具、游戏开发或任何涉及图像处理的应用程序。","2026-06-11 03:04:34","top_language"]