A complete Express.js API server for generating product mockups from artwork images. The server provides RESTful endpoints to process images and generate mockups for various products like t-shirts, mobile covers, curtains, and more.
npm install# Generate maps for all products
./create_maps.sh
# Or generate maps for specific product
./create_maps.sh tshirt# Production mode
npm start
# Development mode (with auto-restart)
npm run devThe server will start on http://localhost:5002
GET /health- Server health checkGET /api/mockup/health- Mockup service health checkGET /api/mockup/products- List available productsGET /api/mockup/products/:product/status- Get product status
POST /api/mockup/generate/:product- Generate mockup for specific productPOST /api/mockup/generate- Generate mockups for all productsPOST /api/mockup/generate-base64/:product- Generate from base64 imagePOST /api/mockup/generate-base64- Generate all from base64 image
GET /api/mockup/docs- API documentation
curl http://localhost:5002/api/mockup/productscurl -X POST \
-F "artwork=@swatches/art1.jpg" \
-F "useDynamic=false" \
-F "useTiling=true" \
http://localhost:5002/api/mockup/generate/tshirtcurl -X POST \
-F "artwork=@swatches/art1.jpg" \
-F "useDynamic=false" \
-F "useTiling=true" \
http://localhost:5002/api/mockup/generatecurl -X POST \
-H "Content-Type: application/json" \
-d '{
"imageData": "data:image/jpeg;base64,/9j/4AAQSkZJRgABA...",
"useDynamic": false,
"useTiling": true
}' \
http://localhost:5002/api/mockup/generate-base64/tshirtmockup/
βββ server.js # Main server file
βββ create_mockup.js # Core mockup generation logic
βββ mockup_processor.js # File processing utilities
βββ test_client.js # API test client
βββ routes/
β βββ mockupRoutes.js # API routes
βββ controllers/
β βββ mockupController.js # Request handlers
βββ utils/
β βββ setup.js # Environment setup utilities
βββ base_images/ # Product templates and masks
βββ maps/ # Generated displacement/lighting maps
βββ mockups/ # Generated mockup outputs
βββ swatches/ # Sample artwork files
- Multiple Product Support: T-shirt, mobile cover, curtain, mug, hoodie
- Flexible Input: File upload, base64 images, image buffers
- Smart Scaling: Automatic artwork scaling to fit mask dimensions
- Tiling Support: Pattern tiling across large surfaces
- Dynamic Positioning: Advanced positioning algorithms
- RESTful Design: Clean, intuitive API endpoints
- CORS Support: Cross-origin requests enabled
- Rate Limiting: 100 requests per 15 minutes per IP
- File Validation: Image type and size validation
- Error Handling: Comprehensive error responses
- Health Monitoring: Service health checks
- Helmet.js: Security headers
- Input Validation: File type and size limits
- Temporary File Cleanup: Automatic cleanup of temp files
- Memory Management: Efficient buffer handling
PORT=5002 # Server port
NODE_ENV=development # Environment modeThe server is configured to accept requests from:
http://localhost:3000http://localhost:3001http://localhost:5000http://localhost:5001http://127.0.0.1:3000http://127.0.0.1:5000
Add your production domains to the CORS configuration in server.js.
- Content-Type:
image/jpeg - Response: Direct image binary data
- Headers:
X-Product: Product nameX-Size: Image size in bytesX-Options: JSON string of options used
{
"success": true,
"results": {
"tshirt": {
"success": true,
"size": 245760,
"product": "tshirt"
},
"mobile_cover": {
"success": true,
"size": 189234,
"product": "mobile_cover"
}
},
"mockups": {
"tshirt": {
"data": "data:image/jpeg;base64,/9j/4AAQSkZJRgABA...",
"size": 245760,
"product": "tshirt"
},
"mobile_cover": {
"data": "data:image/jpeg;base64,/9j/4AAQSkZJRgABA...",
"size": 189234,
"product": "mobile_cover"
}
},
"options": {
"useDynamic": false,
"useTiling": true
}
}{
"success": false,
"error": "Product not ready",
"message": "Missing maps - run ./create_maps.sh tshirt to generate required maps"
}npm test- Start the server:
npm start - Open another terminal
- Run:
node test_client.js
-
"Product not ready"
- Run
./create_maps.sh <product_name>to generate required maps
- Run
-
"ImageMagick not found"
- Install ImageMagick:
sudo apt install imagemagick
- Install ImageMagick:
-
"CORS error"
- Add your domain to the CORS origins in
server.js
- Add your domain to the CORS origins in
-
"File too large"
- Increase the file size limit in
routes/mockupRoutes.js
- Increase the file size limit in
Set NODE_ENV=development for detailed error messages.
import MockupAPIClient from './test_client.js';
const client = new MockupAPIClient();
// Generate t-shirt mockup
const result = await client.generateMockupFromFile('tshirt', 'path/to/image.jpg');
console.log(result.mockupUrl);import requests
# Generate mockup
with open('image.jpg', 'rb') as f:
files = {'artwork': f}
data = {'useDynamic': False, 'useTiling': True}
response = requests.post('http://localhost:5002/api/mockup/generate/tshirt',
files=files, data=data)
result = response.json()
print(result['mockupUrl'])# Generate mockup
curl -X POST \
-F "artwork=@image.jpg" \
-F "useDynamic=false" \
-F "useTiling=true" \
http://localhost:5002/api/mockup/generate/tshirt- File Size Limit: 50MB per request
- Rate Limit: 100 requests per 15 minutes per IP
- Supported Formats: JPEG, PNG, GIF, BMP, WebP
- Processing Time: ~2-5 seconds per mockup (depending on image size)
- Add product folder to
base_images/ - Include
template.jpgandmask.png - Run
./create_maps.sh <product_name> - Restart the server
- Routes:
routes/mockupRoutes.js - Controllers:
controllers/mockupController.js - Core Logic:
create_mockup.js
ISC License - See package.json for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Need help? Check the API documentation at http://localhost:5002/api/mockup/docs when the server is running.