Skip to content

lucassith/pixvert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PIXVERT (pixvert_rs)

About

The sole purpose of this application is to scale images on demand via URL. It supports header and memory cache.

It is similiar to the Piuma Custom project.

Rust language allows for more performance oriented approach than Golang.

This is not production ready yet - if you are interested in more wholesome solution - use Piuma Custom for now.

Docker

Docker image is available here: https://hub.docker.com/r/lucassith/pixvert_rs

Features

  • Fetching images from external source and Cache them with ETAG and/or Modified-Since Headers.
  • Decoding PNG/JPEG images.
  • Scaling images via URL params to a given resolution.
  • Encoding scaled images to WEBP.

Usage

Installation

Clone this repo and run:

cargo run --release

Application is then ready and you will be able to execute HTTP request.

Before you begin

Having an image resource available under: https://via.placeholder.com/150x100

You must first do URI Encode the string to: https%3A%2F%2Fvia.placeholder.com%2F150x100

Possible image formats:

Decode: PNG, JPG

Encode: PNG, JPG, WEBP, JPEG-XL

Example Requests

Cache Image Only

If you want to cache the image, you can execute following request

curl localhost:8080/{encoded url}

example

curl localhost:8080/https%3A%2F%2Fvia.placeholder.com%2F150x100

As a response you will receive exact same image but served from cache.

Change Format + Cache Image

You can change the file format using following request:

curl localhost:8080/{format}/{url}

example

curl localhost:8080/webp/https%3A%2F%2Fvia.placeholder.com%2F150x100

As a response you will receive webp encoded image.

Resize + Cache Image

You can change the file format using following request:

curl localhost:8080/{width}_{height}/{url}

example

curl localhost:8080/100_400/https%3A%2F%2Fvia.placeholder.com%2F150x100

As a response you will receive a scaled image (it will not be exactly 100x400 since the image keeps the ratio)

Resize + Change Format + Cache an image

You can change the file format using following request:

curl localhost:8080/{width}_{height}/webp/{url}

example

curl localhost:8080/100_400/webp/https%3A%2F%2Fvia.placeholder.com%2F150x100

TODO:

  • Handle Cache-Control header when fetching external image.
  • Implement quality parameter.
  • Implement keeping aspect ratio.
  • Implement Cache-Control for response.
  • Configuration file.
  • Implement JPEG-XL for encoding.
  • Implement JPEG-XL for decoding.
  • Maximum output file pixels

About

pixvert_rs web image optimization server

Resources

Stars

Watchers

Forks

Packages

No packages published