refactor: improve logging
Release / check-release (push) Successful in 15s
Release / build_gnu (push) Skipped
Release / build_musl (push) Skipped
Release / build_windows (push) Skipped
Release / package_gnu (deb) (push) Skipped
Release / package_gnu (rpm) (push) Skipped
Release / package_musl (deb) (push) Skipped
Release / package_musl (rpm) (push) Skipped
Release / publish-release (push) Skipped
CI / Test (push) Successful in 1m43s
CI / Build Linux (push) Successful in 1m56s

This commit is contained in:
Elias Wendland
2026-07-16 14:43:58 +02:00
parent d3b7d7a18f
commit b65d5eb97c
8 changed files with 198 additions and 44 deletions
+28 -10
View File
@@ -13,13 +13,15 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::plugin::Plugin;
use image::ImageFormat;
use std::io::Cursor;
use std::path::Path;
pub struct PluginImpl;
impl Plugin for PluginImpl {
#[tracing::instrument(skip(self))]
fn is_available(&self) -> bool {
tracing::trace!("Checking availability for png_to_jpeg plugin (always true)");
true
}
fn name(&self) -> &'static str {
"png_to_jpeg"
}
@@ -39,18 +41,34 @@ impl Plugin for PluginImpl {
220
}
#[tracing::instrument(skip(self, input, _temp_dir))]
fn convert(
&self,
input: &[u8],
_from: &str,
_to: &str,
_temp_dir: &Path,
_temp_dir: &std::path::Path,
) -> Result<Vec<u8>, String> {
let img = image::load_from_memory_with_format(input, ImageFormat::Png)
.map_err(|e| e.to_string())?;
let mut buf = Vec::new();
img.write_to(&mut Cursor::new(&mut buf), ImageFormat::Jpeg)
.map_err(|e| e.to_string())?;
Ok(buf)
tracing::debug!("png_to_jpeg starting conversion");
tracing::trace!("Loading PNG image from memory ({} bytes)", input.len());
let img = image::load_from_memory_with_format(input, image::ImageFormat::Png)
.map_err(|e| {
tracing::error!("Failed to decode PNG image: {}", e);
e.to_string()
})?;
tracing::trace!("PNG image loaded successfully. Dimensions: {}x{}", img.width(), img.height());
let mut output = std::io::Cursor::new(Vec::new());
tracing::trace!("Encoding image as JPEG");
img.write_to(&mut output, image::ImageFormat::Jpeg)
.map_err(|e| {
tracing::error!("Failed to encode image as JPEG: {}", e);
e.to_string()
})?;
let out_bytes = output.into_inner();
tracing::debug!("png_to_jpeg conversion completed. Output size: {} bytes", out_bytes.len());
Ok(out_bytes)
}
}