| Crates.io | shrinkray |
| lib.rs | shrinkray |
| version | 1.0.3 |
| created_at | 2025-11-01 16:27:22.961363+00 |
| updated_at | 2025-12-20 22:25:04.553572+00 |
| description | Lightning-fast image resizing & optimization for the web |
| homepage | https://shrinkray.photo |
| repository | https://github.com/tpyo/shrinkray |
| max_upload_size | |
| id | 1912170 |
| size | 124,627 |
A high-performance Rust library for image processing powered by libvips.
cargo add shrinkray
This library requires libvips 8.17.0 or higher to be installed on your system. For older libvips versions (8.16.x), use shrinkray 1.0.1.
macOS:
brew install vips
Ubuntu/Debian:
apt-get install libvips-dev
Fedora/RHEL:
dnf install vips-devel
use shrinkray::ImageProcessor;
use shrinkray::options::{Format, Fit};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Read input image
let image_bytes = std::fs::read("input.jpg")?;
// Process the image
let result = ImageProcessor::new(&image_bytes)
.resize(800, 600)
.quality(85)
.format(Format::Webp)
.fit(Fit::Crop)
.process()?;
// Save the result
std::fs::write("output.webp", result.bytes())?;
Ok(())
}
let thumbnail = ImageProcessor::new(&image_bytes)
.thumbnail(200) // 200x200 square thumbnail
.process()?;
let filtered = ImageProcessor::new(&image_bytes)
.vintage(80)
.sharpen(40)
.process()?;
let duotone = ImageProcessor::new(&image_bytes)
.duotone(
0, 50, 100, // Shadow colour (dark blue)
255, 165, 0 // Highlight colour (orange)
)
.duotone_alpha(75) // 75% opacity
.process()?;
let trimmed = ImageProcessor::new(&image_bytes)
.rotate(90)
.trim() // Auto-trim transparent/whitespace borders
.process()?;
let cropped = ImageProcessor::new(&image_bytes)
.aspect_ratio(16, 9)
.width(1920)
.fit(Fit::Crop)
.process()?;
let retina = ImageProcessor::new(&image_bytes)
.width(400)
.height(300)
.device_pixel_ratio(2) // Output will be 800x600
.process()?;
width(i32) - Set output widthheight(i32) - Set output heightresize(i32, i32) - Set both width and heightthumbnail(i32) - Create square thumbnailfit(Fit) - Resize behavior (Crop, Clip, Max)device_pixel_ratio(i32) - DPR multiplieraspect_ratio(i32, i32) - Target aspect ratioformat(Format) - Output format (Jpeg, Png, Webp, Avif)quality(i32) - Quality 1-100 (default: 75)lossless(bool) - Enable lossless compressionrotate(u16) - Rotate 90, 180, or 270 degreessharpen(u8) - Sharpening intensity 1-100blur(u8) - Blur amount 1-100trim() - Auto-trim borderstrim_colour(u8, u8, u8) - Trim specific colourbackground(u8, u8, u8) - Background colour for padding/flatteninggrayscale() - Convert to grayscalemonochrome(u8) - Monochrome with intensitysepia(u8) - Sepia tone filtervintage(u8) - Vintage film effectpolaroid(u8) - Polaroid effectkodachrome(u8) - Kodachrome film simulationtechnicolor(u8) - Technicolor effecttint(u8, u8, u8) - Colour tint overlayduotone(u8, u8, u8, u8, u8, u8) - Duotone with shadow and highlight coloursduotone_alpha(u8) - Duotone opacity 1-100max_megapixels(f64) - Maximum input image sizemax_output_resolution(u32) - Maximum output dimensionThe process() method returns a ProcessedImage with these methods:
bytes(&self) -> &[u8] - Get image bytes as a sliceinto_bytes(self) -> Vec<u8> - Consume and get owned bytesformat(&self) -> Format - Get the output formatmime_type(&self) -> &'static str - Get MIME type stringThis library powers the shrinkray image server, which provides:
See the main repository for the complete server implementation.
MIT License - see LICENSE for details.