Welcome to the ImageLab platform documentation. This unified guide contains the System Architecture, Installation & Deployment Procedures, REST API Specifications, User Guide, and Administrative System Guide.
This diagram shows how web clients interact with the ImageLab web application (Apache/PHP), local file storage, the MySQL/MariaDB database, shell wrappers (ImageMagick/Pillow fallbacks), and the background FastAPI Python microservice.
graph TD
User([Web Browser Client]) <-->|HTTPS / HTTP| WebServer[Apache / Nginx Web Server]
subgraph Web Application [ImageLab PHP Core]
WebServer <--> PHP[PHP-FPM Core Engine]
PHP <--> Config[Config.php & Core Services]
Config <--> Validator[Validator Path & MIME Security]
end
subgraph Database Layer
PHP <-->|PDO Connection| MySQL[(MySQL / MariaDB Database)]
end
subgraph File Storage [Local Disk Directory]
Config <-->|Reads/Writes| UploadsDir[uploads/]
Config <-->|Writes| ProcessedDir[processed/]
Config <-->|Writes| TempDir[temp/]
Config <-->|Appends| LogsDir[logs/imagemagick.log]
end
subgraph Processing Workers [Execution Layer]
PHP -->|exec shell arg| MagickWrapper[bin/magick.bat Wrapper]
MagickWrapper -->|Invokes Python| FallbackPy[ai-service/magick_fallback.py]
FallbackPy -->|Manipulates Files| ProcessedDir
PHP -->|cURL requests| AIMicroservice[FastAPI AI Microservice :8000]
AIMicroservice -->|Runs PyTorch/OpenCV| PyScripts[Upscale/Face/No-BG PyScripts]
PyScripts -->|Manipulates Files| ProcessedDir
end
This diagram maps out the database tables, fields, types, and foreign key relationships that drive the SaaS Billing, User roles, API gateway rate limits, and async jobs.
erDiagram
users {
int id PK
string name
string email UK
string password
string role
tinyint email_verified
string verification_token
string reset_token
timestamp reset_token_expires
string remember_token
int failed_attempts
timestamp lockout_until
timestamp created_at
timestamp updated_at
}
projects {
int id PK
int user_id FK
string project_name
longtext project_data
timestamp created_at
timestamp updated_at
}
subscriptions {
int id PK
int user_id FK
string plan
string status
int credits
timestamp starts_at
timestamp ends_at
timestamp created_at
timestamp updated_at
}
transactions {
int id PK
int user_id FK
string transaction_id UK
decimal amount
string currency
string status
string provider
timestamp created_at
}
invoices {
int id PK
int user_id FK
string invoice_number UK
decimal amount
decimal tax
string status
timestamp billing_date
timestamp created_at
}
api_keys {
int id PK
int user_id FK
string api_key UK
string name
string status
timestamp created_at
timestamp last_used_at
}
usage_logs {
int id PK
int user_id FK
int api_key_id FK
string action
text details
int bytes
timestamp created_at
}
audit_logs {
int id PK
int user_id FK
string action
string ip_address
string user_agent
text details
timestamp created_at
}
notifications {
int id PK
int user_id FK
string type
string title
text message
tinyint is_read
timestamp created_at
}
conversion_history {
int id PK
string original_filename
string processed_filename
string operation
int file_size_before
int file_size_after
timestamp created_at
}
queue_jobs {
int id PK
string filename
string operation
string status
timestamp created_at
timestamp updated_at
}
enhancement_history {
int id PK
string filename
string operation
string value
timestamp created_at
}
saved_presets {
int id PK
string preset_name
text preset_data
timestamp created_at
}
ai_jobs {
int id PK
string image_path
string operation
string status
string result_path
text error_message
timestamp created_at
timestamp updated_at
}
users ||--o{ projects : "creates"
users ||--o{ subscriptions : "owns"
users ||--o{ transactions : "makes"
users ||--o{ invoices : "receives"
users ||--o{ api_keys : "manages"
users ||--o{ usage_logs : "tracks"
users ||--o{ audit_logs : "records"
users ||--o{ notifications : "reads"
api_keys ||--o{ usage_logs : "authorizes"
This flowchart outlines the authorization checks, rates checking, routing, execution, and consumption logging performed inside the developer gateway.
graph TD
Req[Developer HTTP API Request] --> CheckKey{Has API Key?}
CheckKey -->|No| Err401[Response: 401 API Key Required]
CheckKey -->|Yes| ValidKey{Is Key Valid in DB?}
ValidKey -->|No| Err401_2[Response: 401 Invalid Key]
ValidKey -->|Yes| PlanAccess{Plan has API Access?}
PlanAccess -->|No| Err403[Response: 403 Plan Disabled]
PlanAccess -->|Yes| RateLimit{Within Daily Rate Limit?}
RateLimit -->|No| Err429[Response: 429 Rate Limit Exceeded]
RateLimit -->|Yes| Route{Identify Endpoint}
Route -->|upload| ActionUpload[Save to uploads/ & check quota]
Route -->|convert| ActionConvert[Call convertImage]
Route -->|resize| ActionResize[Call resizeImage]
Route -->|enhance| ActionEnhance[Apply Slider Filters]
Route -->|upscale| ActionUpscale[Check/Consume Credits -> Call AI microservice]
Route -->|remove-bg| ActionBG[Check/Consume Credits -> Call AI microservice]
ActionUpload & ActionConvert & ActionResize & ActionEnhance & ActionUpscale & ActionBG --> LogUsage[Insert usage_logs record]
LogUsage --> Res200[Response: 200 JSON Success Payload]
This guide details instructions for setting up the ImageLab platform on both local development machines and production Linux environments.
Before you start, make sure you have the following installed:
- PHP: version
8.1or higher. Ensure these PHP modules are enabled inphp.ini:pdo_mysql,gd,fileinfo,mbstring,openssl,curl,zip,xml
- Database: MySQL
8.0or MariaDB10.5 - Web Server: Apache Server (with
mod_rewriteenabled to support.htaccessrewrite rules) or Nginx - Python: version
3.9or higher (necessary if deploying AI/FastAPI services)
- Clone/Move Codebase:
- Move the project folder inside your local server web root:
- Laragon:
C:\laragon\www\ImageLab - XAMPP:
C:\xampp\htdocs\ImageLab
- Laragon:
- Move the project folder inside your local server web root:
- Setup MySQL Database:
- Launch Laragon/XAMPP and turn on Apache and MySQL.
- Access phpMyAdmin or connect using terminal and execute:
CREATE DATABASE imagelab CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
- Import the database structure from the repository:
mysql -u root -p imagelab < imagelab_sql.sql
- Database Credentials:
- Open core/Config.php and verify database settings:
public const DB_HOST = 'localhost'; public const DB_NAME = 'imagelab'; public const DB_USER = 'root'; public const DB_PASS = '';
- Open core/Config.php and verify database settings:
- Access UI:
- Open the browser and visit:
http://localhost/ImageLab/public/
- Open the browser and visit:
Follow these terminal instructions to build the server stack on Ubuntu:
sudo apt update && sudo apt upgrade -y
# Install Nginx, MySQL, PHP 8.2-FPM & extensions, python venv
sudo apt install -y nginx mysql-server php8.2-fpm php8.2-mysql php8.2-gd php8.2-curl php8.2-mbstring php8.2-xml php8.2-zip python3 python3-pip python3-venv curl gitsudo mysql_secure_installation
# Connect to create user and database
sudo mysql -u root -pInside MySQL console run:
CREATE DATABASE imagelab CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'imagelab_prod'@'localhost' IDENTIFIED BY 'HighEntropySecurePassword987!';
GRANT ALL PRIVILEGES ON imagelab.* TO 'imagelab_prod'@'localhost';
FLUSH PRIVILEGES;
EXIT;Import the schema:
mysql -u imagelab_prod -p imagelab < /var/www/imagelab/imagelab_sql.sqlIf deploying the background FastAPI AI microservice:
cd /var/www/imagelab/ai-service
python3 -v venv venv
source venv/bin/activate
pip install -r requirements.txtCreate the configuration file: /etc/nginx/sites-available/imagelab
server {
listen 80;
server_name yourdomain.com;
root /var/www/imagelab/public;
index index.php index.html;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(ht|git) {
deny all;
}
}Enable server block and reload:
sudo ln -s /etc/nginx/sites-available/imagelab /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginxPermissions must allow the web server (www-data) to write uploads and processed files:
sudo chown -R www-data:www-data /var/www/imagelab
sudo chmod -R 775 /var/www/imagelab/uploads
sudo chmod -R 775 /var/www/imagelab/processed
sudo chmod -R 775 /var/www/imagelab/logs
sudo chmod -R 775 /var/www/imagelab/tempBackground workers compile queue actions.
To ensure queue runs continuously in the background, create a systemd configuration file at /etc/systemd/system/imagelab-worker.service:
[Unit]
Description=ImageLab Background Jobs Queue Worker
After=mysql.service
[Service]
Type=simple
User=www-data
ExecStart=/usr/bin/php /var/www/imagelab/bin/queue_worker.php
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targetEnable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable imagelab-worker
sudo systemctl start imagelab-workerThe developer API gateway allows external systems to securely upload and process images.
Authenticate requests by providing your API key (il_...) in the request header or as a query parameter.
- Header (Recommended):
X-API-Key: il_your_api_key_here - Query Parameter:
?api_key=il_your_api_key_here
POST http://yourdomain.com/api/v1/api_gateway.php?endpoint={action}
- Endpoint:
/api_gateway.php?endpoint=upload - Method:
POST - Body Type:
multipart/form-data - Parameters:
image(File, Required): The image file payload (max 10MB).
- Sample Response:
{
"success": true,
"status": "success",
"message": "Image uploaded successfully!",
"data": {
"filename": "7f6d84496226e562e876476a623595f1.png",
"original_name": "photo.png",
"size": 29236,
"width": 150,
"height": 99,
"extension": "png"
}
}- Endpoint:
/api_gateway.php?endpoint=convert - Method:
POST - Body Type:
application/x-www-form-urlencoded - Parameters:
filename(String, Required): The unique filename returned from upload.format(String, Required): The target format (jpg,png,webp,gif,bmp,tiff).
- Sample Response:
{
"success": true,
"status": "success",
"message": "Conversion complete.",
"data": {
"filename": "7f6d84496226e562e876476a623595f1.webp",
"original_format": "png",
"converted_format": "webp",
"size": 19430,
"width": 150,
"height": 99
}
}- Endpoint:
/api_gateway.php?endpoint=resize - Method:
POST - Body Type:
application/x-www-form-urlencoded - Parameters:
filename(String, Required): The unique filename.width(Int, Optional): Target width in pixels (0 for auto).height(Int, Optional): Target height in pixels (0 for auto).maintainRatio(Int, Optional):1to preserve ratio (default),0to stretch.
- Sample Response:
{
"success": true,
"status": "success",
"message": "Resize complete.",
"data": {
"filename": "7f6d84496226e562e876476a623595f1_resized.png",
"size": 12894,
"width": 100,
"height": 66
}
}- Endpoint:
/api_gateway.php?endpoint=enhance - Method:
POST - Body Type:
application/x-www-form-urlencoded - Parameters:
filename(String, Required): The unique filename.brightness(Int, Optional): Exposure adjustment value (-100to100).contrast(Int, Optional): Contrast adjustment value (-100to100).saturation(Int, Optional): Saturation adjustment value (-100to100).
- Sample Response:
{
"success": true,
"status": "success",
"message": "Enhancement applied.",
"data": {
"filename": "7f6d84496226e562e876476a623595f1_api_enhance.png",
"size": 28450
}
}- Endpoint:
/api_gateway.php?endpoint=upscale - Method:
POST - Body Type:
application/x-www-form-urlencoded - Parameters:
filename(String, Required): The unique filename.
- Sample Response:
{
"success": true,
"status": "success",
"message": "AI Upscaling complete.",
"data": {
"filename": "7f6d84496226e562e876476a623595f1_api_upscale.png",
"size": 184590
}
}- Endpoint:
/api_gateway.php?endpoint=remove-background - Method:
POST - Body Type:
application/x-www-form-urlencoded - Parameters:
filename(String, Required): The unique filename.
- Sample Response:
{
"success": true,
"status": "success",
"message": "AI Background Removal complete.",
"data": {
"filename": "7f6d84496226e562e876476a623595f1_api_nobg.png",
"size": 94820
}
}- Create Account: Visit the registration page. Upon signing up, you receive the Free Plan by default (which allocates 5 daily AI credits, 50MB space).
- Upgrade Plans:
- Visit the billing/subscriptions panel.
- Select a plan tier:
- Starter ($10.99/mo): 100 AI credits, 500MB cloud space, API key generation access.
- Professional ($29.99/mo): 500 AI credits, 5GB cloud space, API access.
- Enterprise ($99.99/mo): Unlimited operations, 50GB cloud space, API access.
- Sandbox payment simulations can be run directly using the PayPal mock layout.
- Convert Tab: Convert files to WebP, JPEG, PNG, or GIF. The converted image is displayed next to the original inside the comparison view.
- Resize Tab: Resize images using custom dimensions or platform presets (Instagram Post, YouTube Thumbnail, etc.).
- Advanced Resizer: You can chain resizes together. Once resized, you can immediately resize the output image again (on top of the current dimensions) by inputting new numbers and hitting Apply.
- Compress Tab: Optimize images by selecting preset options (Low, Medium, High, Max) to compress file sizes with minimal quality degradation.
- Canvas Tab: Interactive editor powered by Fabric.js.
- Smart Crop: Click "Crop Mode" to display a crop outline frame. Click and drag the white corner handles to highlight crop areas, and click "Execute Crop".
- Text Watermarks: Input custom text, adjust size, transparency, and click "Add Text" to layer watermarks.
- AI Editor Tab:
- Auto-Enhance: Analyzes the image and corrects color temperature casts, exposure levels, and white balance settings automatically.
- Super Resolution: Upscales images (2x or 4x) using AI models while maintaining details.
- Remove Background: Isolates subjects and removes backgrounds to output transparent PNGs.
Administrative users can manage system assets, promote users, review analytics charts, and monitor background tasks.
Access the Admin control panel by logging in as an administrator (standard seed: admin@imagelab.com / password admin).
The admin landing page provides aggregate metrics:
- User Accounts: Manage user profiles, active keys, billing history, or delete users.
- Revenue Logs: Track monthly subscriptions transaction logs.
- Storage Metrics: Total size of cloud files on disk across
uploads/andprocessed/folders.
- Search for any user by name or email.
- Modify roles directly (e.g. promote a user to
premiumoradmin). - Edit credits balances to grant manual AI operational requests.
- Clear lockouts if standard users block their profiles (occurring automatically after 5 consecutive incorrect passwords).
Review service operations and metrics using the dynamic Chart.js dashboards:
- Active Logins: Tracks authentications over a rolling 7-day period.
- Revenue growth: Line charts monitoring subscription billing.
- Feature Share: Pie charts comparing the usage share of Conversions, Resizes, Compression, and AI requests.
Background jobs are queued inside the database ai_jobs and queue_jobs tables.
If execution errors occur (e.g. Queue Job #10 failed or Python execution failed):
- Inspect Log Files:
- API Gateway and Python connection failures are logged under logs/ai_error.log.
- ImageMagick shell errors are logged under logs/imagemagick.log.
- Review DB State:
- Open the database management panel or use the admin queue section to review the specific job record (which contains the full Python traceback message under
error_message).
- Open the database management panel or use the admin queue section to review the specific job record (which contains the full Python traceback message under
- Queue Controls (UI):
- Cancel Queue: Terminates all currently queued or processing async jobs.
- Clear History: Wipes the queue database table logs to keep database storage lightweight.