Fuel Tank API Documentation
API Endpoints
GET /api/fuel-image
Generates a dynamic fuel tank image based on current fuel level and capacity.
Query Parameters:
capacity(number) - The total capacity of the fuel tank in literscurrent(number) - The current fuel level in literspercent(string, optional) - Display percentage (e.g., "75%" or "75"). If provided, shows percentage instead of liters
Response:
Returns a PNG image with the following features:
- Visual representation of the fuel level
- Color-coded indicators (green for normal, red for low)
- Current fuel level displayed in liters (or percentage if percent provided)
- Status bar showing percentage filled
Example Usage:
GET /api/fuel-image?capacity=100¤t=75This will return an image showing a tank that is 75% full with 75L of fuel.
GET /api/fuel-image?capacity=100¤t=75&percent=75%This will show "75%" instead of "75L" in the gauge display.
Live Example:
75% Full (Normal)
5% Full (Low)
No Data
GET /api/vehicle-image
Generates a dynamic vehicle image with two fuel tanks based on current fuel levels and capacities.
Query Parameters:
capacity1(number) - The total capacity of the first fuel tank in literscurrent1(number) - The current fuel level of the first tank in literspercent1(string, optional) - Display percentage for tank 1 (e.g., "75%" or "75"). If provided, shows percentage instead of literscapacity2(number) - The total capacity of the second fuel tank in literscurrent2(number) - The current fuel level of the second tank in literspercent2(string, optional) - Display percentage for tank 2 (e.g., "75%" or "75"). If provided, shows percentage instead of litersformat(string, optional) - Output format: 'svg' (animated) or 'webp' (default: 'svg')
Response:
Returns an image (SVG or WebP) with the following features:
- Vehicle with two fuel tanks visualized
- Animated water-like effect in SVG format
- Color-coded indicators (green for normal, orange for warning, red for critical)
- Current fuel levels displayed in liters (or percentage if percent1/percent2 provided)
- Status bars showing percentage filled
Example Usage:
Basic usage with two tanks (displays liters):
GET /api/vehicle-image?capacity1=20000¤t1=20000&capacity2=20000¤t2=5000Returns an image showing a vehicle with the first tank 100% full (20000L) and the second tank 25% full (5000L).
Single tank only:
GET /api/vehicle-image?capacity1=20000¤t1=15000Shows a single, larger tank that is 75% full (15000L).
Display percentage instead of liters:
GET /api/vehicle-image?capacity1=20000¤t1=15000&percent1=75%Shows "75%" instead of "15000L" in the gauge display.
Both tanks with percentage display:
GET /api/vehicle-image?capacity1=20000¤t1=20000&percent1=100%&capacity2=20000¤t2=5000&percent2=25%Shows "100%" and "25%" instead of liters for both tanks.
WebP format output:
GET /api/vehicle-image?capacity1=20000¤t1=15000&percent1=75%&format=webpReturns a WebP image instead of SVG (no animation)..
Live Example:
Both Tanks Full
One Tank Low
No Data
Single Tank Only
Implementation Details
The API uses the following technologies:
- Next.js API Routes - For serverless API functionality
- Sharp - For image processing and manipulation
- SVG - For dynamic overlays and text rendering
Error Handling
- 404 - Returned when the base tank image cannot be found
- 500 - Returned when there's an error processing the image