1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! Image manipulation utilities using `libvips`.
//!
//! This module provides high-performance image processing using the libvips library.
//! Libvips is a demand-driven, horizontally threaded image processing library that
//! is significantly faster than pure Rust implementations for large images.
//!
//! # Features
//!
//! * High-performance image resizing from files
//! * Resize from byte buffers
//! * Error handling utilities for libvips
//! * Automatic color profile management (sRGB)
//! * Thread-safe operations with lazy initialization
//!
//! # Platform Support
//!
//! This module is not available on Windows platforms.
//!
//! # Examples
//!
//! ```rust,no_run
//! # #[cfg(all(not(target_os = "windows"), feature = "libvips"))]
//! # {
//! use moosicbox_image::libvips::resize_local_file;
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Resize an image to 800x600
//! let resized = resize_local_file(800, 600, "/path/to/image.jpg")?;
//! # Ok(())
//! # }
//! # }
//! ```
use LazyLock;
use Bytes;
use ;
use debug;
static VIPS: = new;
/// Gets and clears the current libvips error buffer.
///
/// # Panics
///
/// Panics if the libvips library cannot be initialized on first access.
/// Resizes an image file using libvips.
///
/// # Errors
///
/// * [`libvips::error::Error`] - If the image file cannot be loaded
/// * [`libvips::error::Error`] - If the thumbnail generation fails
/// * [`libvips::error::Error`] - If the image encoding to JPEG fails
///
/// # Panics
///
/// Panics if the libvips library cannot be initialized on first access.
///
/// # Examples
///
/// ```rust,no_run
/// # #[cfg(all(not(target_os = "windows"), feature = "libvips"))]
/// # {
/// use moosicbox_image::libvips::resize_local_file;
///
/// # fn main() -> Result<(), libvips::error::Error> {
/// let bytes = resize_local_file(1024, 1024, "./cover.jpg")?;
/// assert!(!bytes.is_empty());
/// # Ok(())
/// # }
/// # }
/// ```
/// Resizes image data from a byte buffer using libvips.
///
/// # Errors
///
/// * [`libvips::error::Error`] - If the image buffer cannot be decoded
/// * [`libvips::error::Error`] - If the thumbnail generation fails
/// * [`libvips::error::Error`] - If the image encoding to JPEG fails
///
/// # Panics
///
/// Panics if the libvips library cannot be initialized on first access.
///
/// # Examples
///
/// ```rust,no_run
/// # #[cfg(all(not(target_os = "windows"), feature = "libvips"))]
/// # {
/// use moosicbox_image::libvips::resize_bytes;
///
/// # fn main() -> Result<(), libvips::error::Error> {
/// let source = std::fs::read("./cover.jpg").expect("cover image should exist");
/// let bytes = resize_bytes(512, 512, &source)?;
/// assert!(!bytes.is_empty());
/// # Ok(())
/// # }
/// # }
/// ```