{"id":13597332,"url":"https://github.com/gaucho-labs/leptos-image","last_synced_at":"2026-01-17T21:59:44.569Z","repository":{"id":181707891,"uuid":"667174195","full_name":"gaucho-labs/leptos-image","owner":"gaucho-labs","description":"An optimized Image component for Leptos","archived":false,"fork":false,"pushed_at":"2024-04-08T19:00:26.000Z","size":3790,"stargazers_count":63,"open_issues_count":8,"forks_count":14,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-14T11:33:14.354Z","etag":null,"topics":["image-optimization","leptos","rust","ssr"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gaucho-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-16T22:07:12.000Z","updated_at":"2026-01-07T15:12:42.000Z","dependencies_parsed_at":"2024-11-06T21:35:42.423Z","dependency_job_id":"fb7ec184-433f-4c71-bb6f-9ba04e6b90d6","html_url":"https://github.com/gaucho-labs/leptos-image","commit_stats":null,"previous_names":["nicoburniske/leptos_image","nicoburniske/leptos-image","gaucho-labs/leptos-image"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/gaucho-labs/leptos-image","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaucho-labs%2Fleptos-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaucho-labs%2Fleptos-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaucho-labs%2Fleptos-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaucho-labs%2Fleptos-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gaucho-labs","download_url":"https://codeload.github.com/gaucho-labs/leptos-image/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaucho-labs%2Fleptos-image/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28519254,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T18:55:29.170Z","status":"ssl_error","status_checked_at":"2026-01-17T18:55:03.375Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["image-optimization","leptos","rust","ssr"],"created_at":"2024-08-01T17:00:30.765Z","updated_at":"2026-01-17T21:59:44.541Z","avatar_url":"https://github.com/gaucho-labs.png","language":"Rust","funding_links":[],"categories":["Components"],"sub_categories":["Unofficial"],"readme":"# Leptos Image\n\n[![Crates.io](https://img.shields.io/crates/v/leptos_image.svg)](https://crates.io/crates/leptos_image)\n[![docs.rs](https://docs.rs/leptos_image/badge.svg)](https://docs.rs/leptos_image)\n\n\u003e Crafted with inspiration from Next.js\n\nImages make a substantial impact on the size and performance of a website, so why not get them right?\n\nEnter Leptos `\u003cImage/\u003e`, a component that enhances the standard HTML `\u003cimg\u003e` element with automatic image optimization features.\n\n## Features\n\n- **Size Optimization**: Automatically resizes images and converts them to the modern `.webp` format for an optimal balance of size and quality.\n- **Low-Quality Image Placeholders (LQIP)**: Embeds SVG placeholders extracted from original images into server-side rendered HTML, improving perceived performance during image loading.\n- **Faster Page Load**: Prioritizes critical images, impacting Largest Contentful Paint (LCP), with the `priority` prop by adding a preload `\u003clink\u003e` to the document head, accelerating load times.\n\n## Version compatibility for Leptos and Leptos Image\n\nThe table below shows the compatible versions of `leptos_image` for each `leptos` version. Ensure you are using compatible versions to avoid potential issues.\n\n| `leptos` version | `leptos_image` version |\n|------------------|------------------------|\n| 0.6.*            | 0.2.*                  |\n\n\n## Installation\n\nTo add `leptos_image` to your project, use cargo:\n\n```bash\ncargo add leptos_image --optional\n```\n\nEnable the SSR feature in your `Cargo.toml`:\n\n```toml\n[features]\nssr = [\n    \"leptos_image/ssr\",\n    # other dependencies...\n]\n\nhydrate = [\n    \"leptos_image/hydrate\", \n    # other dependencies...\n]\n```\n\n## Quick Start\n\n\u003e This requires SSR + Leptos Axum integration\n\n1. **Provide Image Context**: Initialize your Leptos application with `leptos_image::provide_image_context` to grant it read access to the image cache.\n\n    ```rust\n    use leptos::*;\n\n    #[component]\n    fn App() -\u003e impl IntoView {\n        leptos_image::provide_image_context();\n        // Your app content here\n    }\n    ```\n\n2. **Axum State Configuration**: Incorporate `ImageOptimizer` into your app's Axum state.\n\n    ```rust\n    // Composite App State with the optimizer and leptos options.\n    #[derive(Clone, axum::extract::FromRef)]\n    struct AppState {\n        leptos_options: leptos::LeptosOptions,\n        optimizer: leptos_image::ImageOptimizer,\n    }\n\n    ```\n\n3. **Integrate with Router**: Ensure your `ImageOptimizer` is available during SSR of your Leptos App.\n    - Add Image Cache Route: Use `image_cache_route` to serve cached images.\n    - Add `ImageOptimizer` to your App state.\n    - Add `ImageOptimizer` to Leptos Context: Provide the optimizer to Leptos context using `leptos_routes_with_context`.\n\n    ```rust\n    use leptos::*;\n    use leptos_axum::*;\n    use leptos_image::*;\n\n    async fn main() {\n        // Get Leptos options from configuration.\n        let conf = get_configuration(None).await.unwrap();\n        let leptos_options = conf.leptos_options;\n        let root = leptos_options.site_root.clone();\n\n        // Create App State with ImageOptimizer.\n        let state = AppState {\n            leptos_options,\n            optimizer: ImageOptimizer::new(\"/__cache/image\", root, 1),\n        };\n\n        // Create your router\n        let app = Router::new()\n            .route(\"/api/*fn_name\", post(handle_server_fns))\n             // Add a handler for serving the cached images.\n            .image_cache_route(\u0026state)\n            // Provide the optimizer to leptos context.\n            .leptos_routes_with_context(\u0026state, routes, state.optimizer.provide_context(), App)\n            .fallback(fallback_handler)\n            // Provide the state to the app.\n            .with_state(state);\n    }\n    ```\n\n\nA full working example is available in the [examples](./example/start-axum) directory.\n\nNow you can use the Image Component anywhere in your app!\n\n```rust\n#[component]\npub fn MyImage() -\u003e impl IntoView {\n    view! {\n        \u003cImage\n            src=\"/cute_ferris.png\"\n            blur=true\n            width=750\n            height=500\n            quality=85\n        /\u003e\n    }\n}\n```\n\nThis setup ensures your Leptos application is fully equipped to deliver optimized images, enhancing the performance and user experience of your web projects.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaucho-labs%2Fleptos-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgaucho-labs%2Fleptos-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaucho-labs%2Fleptos-image/lists"}