Easily resize images from any URL without manually downloading and uploading them
342
PixRelay is a fast and efficient image processing service. With PixRelay, you can easily resize images from any URL without manually downloading and uploading them.
docker pull alfatta/pixrelay
# With caching enabled (default)
docker run -d -p 3000:3000 -v $(pwd)/cache:/app/cache alfatta/pixrelay
# With caching disabled
docker run -d -p 3000:3000 -e USE_CACHE=false alfatta/pixrelay
# With custom port
docker run -d -p 8080:8080 -e PORT=8080 alfatta/pixrelay
docker-compose.yml file:version: "3.8"
services:
app:
image: alfatta/pixrelay
ports:
- "3000:3000"
volumes:
- ./cache:/app/cache
environment:
- USE_CACHE=true # Optional, defaults to true
- PORT=3000 # Optional, defaults to 3000
docker compose up -d
USE_CACHE: Enable/disable caching (default: true)PORT: Server port (default: 3000)Resize an image to a specific width (maintains aspect ratio):
GET http://localhost:3000/img/{encodedUrl}/resize?size=300
Example:
# Resize image to 300px width
curl "http://localhost:3000/img/aHR0cHM6Ly9leGFtcGxlLmNvbS9pbWFnZS5qcGc/resize?size=300"
Resize and crop an image to specific dimensions:
GET http://localhost:3000/img/{encodedUrl}/fit?size=300x200
Example:
# Resize and crop image to 300x200px
curl "http://localhost:3000/img/aHR0cHM6Ly9leGFtcGxlLmNvbS9pbWFnZS5qcGc/fit?size=300x200"
Before using the API, you need to encode your image URLs. Here's how:
const encodeUrl = (url) => {
return Buffer.from(url)
.toString("base64")
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
};
// Example
const imageUrl = "https://example.com/image.jpg";
const encodedUrl = encodeUrl(imageUrl);
console.log(encodedUrl);
import base64
def encode_url(url):
encoded = base64.urlsafe_b64encode(url.encode()).decode()
return encoded.rstrip('=')
# Example
image_url = 'https://example.com/image.jpg'
encoded_url = encode_url(image_url)
print(encoded_url)
echo -n "https://example.com/image.jpg" | base64 | tr '+/' '-_' | tr -d '='
Long URLs:
Caching:
./cache directoryUSE_CACHE=falseOutput Format:
Error Handling:
<img
src="http://localhost:3000/img/aHR0cHM6Ly9leGFtcGxlLmNvbS9pbWFnZS5qcGc/resize?size=300"
alt="Resized Image"
/>
.thumbnail {
background-image: url("http://localhost:3000/img/aHR0cHM6Ly9leGFtcGxlLmNvbS9pbWFnZS5qcGc/fit?size=150x150");
}
const imageUrl = "https://example.com/large-image.jpg";
const encodedUrl = encodeUrl(imageUrl);
const resizedUrl = `http://localhost:3000/img/${encodedUrl}/resize?size=300`;
MIT
Content type
Image
Digest
sha256:9b3069cd1…
Size
194 MB
Last updated
over 1 year ago
docker pull alfatta/pixrelay