image-optimizer 1.3.0

CLI tool for optimizing images (JPEG, PNG, WebP)
Documentation
use anyhow::Result;
use std::path::{Path, PathBuf};

/// Ensures the output directory structure exists and returns the output file path
///
/// # Errors
/// Returns an error if directory creation fails or path operations are invalid
pub fn ensure_output_dir(
    output_path: &Path,
    input_path: &Path,
    file_path: &Path,
) -> Result<PathBuf> {
    let relative_path = file_path.strip_prefix(input_path)?;
    let output_file_path = output_path.join(relative_path);

    if let Some(parent) = output_file_path.parent() {
        std::fs::create_dir_all(parent)?;
    }

    Ok(output_file_path)
}