tonhowtf/omniget · error

não codifiquei o JPEG

Error message

não codifiquei o JPEG: {}

What it means

Encoder failure in encode_jpeg: the image crate's JpegEncoder rejected the RGB buffer or failed mid-write (unsupported dimensions, I/O on the in-memory cursor, or encoder panic captured as an error), so no JPEG bytes are returned for this quality attempt.

Solutions

  1. Verify the input DynamicImage has non-zero dimensions
  2. Retry with a different quality value; the binary search may hit edge cases
  3. Convert to rgb8 explicitly before encoding if the input layout is unusual
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at src-tauri/omniget-core/src/core/tools/image_compress.rs:72 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/495fa3ad9134e6d0. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/image_compress.rs:72

    pub height: u32,
    pub scaled: bool,
    pub hit_target: bool,
    pub ok: bool,
    pub error: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
pub struct CompressResult {
    pub items: Vec<CompressItem>,
    pub bytes_before: u64,
    pub bytes_after: u64,
}

pub fn encode_jpeg(img: &DynamicImage, quality: u8) -> anyhow::Result<Vec<u8>> {
    let mut buf = Cursor::new(Vec::new());
    let mut enc = JpegEncoder::new_with_quality(&mut buf, quality.clamp(1, 100));
    enc.encode_image(&img.to_rgb8())
        .map_err(|e| anyhow!("não codifiquei o JPEG: {}", e))?;
    Ok(buf.into_inner())
}

/// Busca binária da qualidade que cabe no alvo. Devolve `(bytes, qualidade)`
/// com a **maior** qualidade que ainda cabe; se nem no mínimo couber, devolve
/// a do mínimo para quem chamou decidir se encolhe a imagem.
pub fn fit_quality(
    img: &DynamicImage,
    target_bytes: u64,
    min_quality: u8,
    max_quality: u8,
) -> anyhow::Result<(Vec<u8>, u8, bool)> {
    let (mut lo, mut hi) = (min_quality.max(1), max_quality.min(100));
    let mut best: Option<(Vec<u8>, u8)> = None;
    // 7 passos cobrem a faixa 1-100 com folga.
    for _ in 0..7 {
        if lo > hi {
            break;

View on GitHub (pinned to 8600b91f42)