A PHP-based service that analyzes images using the Google Gemini Vision API. Simply send a Base64-encoded image with a prompt to get AI-powered analysis and detailed descriptions.
Repository: github.com/TheSmartDevs/Image-Info-API
- Image Analysis: Extract detailed information from images using AI
- Format Support: JPEG, PNG, WEBP
- Size Limit: 5MB maximum image size
- CORS Support: Configured for cross-origin requests
- Health Endpoint: Easy verification of API status
- Powered by Google: Uses advanced Gemini Vision API for analysis
To host this API, you need:
- Web server with PHP 7.4 or newer
- PHP cURL extension enabled
- Google API key from Google AI Studio
- Domain with cPanel or similar hosting control panel
Follow these steps to host the Image Info API on your domain:
-
Obtain a Google API Key
- Visit Google AI Studio
- Sign in and generate a new API key
- Replace the placeholder in
image.php
(line:$apiKey = 'YOUR_API_KEY';
)
-
Upload the API File
- Login to your hosting provider's control panel
- Navigate to the public directory (e.g.,
public_html
) - Upload
image.php
to your desired location - Set appropriate file permissions (644 recommended)
-
Verify the Installation
- Access the API at
https://yourdomain.com/image.php
- Use the GET endpoint to confirm it's working
- Access the API at
-
Implement Security Measures
- Use HTTPS encryption
- Consider adding authentication or rate-limiting
- Rotate your Google API key regularly
- Restrict API key usage in Google AI Studio
The API provides two endpoints:
Endpoint: https://yourdomain.com/image.php
Method: GET
Response: API status, endpoints, and limits
Example Request:
curl https://yourdomain.com/image.php
Example Response:
{
"status": "ImageAI API is operational and Powered by @TheSmartDev and @nkka404",
"endpoints": {
"post": "/image.php (with {imageBase64, prompt} in body)"
},
"limits": {
"max_image_size": "5MB",
"supported_formats": "JPEG, PNG, WEBP"
}
}
Endpoint: https://yourdomain.com/image.php
Method: POST
Content-Type: application/json
Request Body Parameters:
imageBase64
: Base64-encoded image (required)mimeType
: Image MIME type (optional, default:image/jpeg
)prompt
: Analysis prompt (optional, default: "Describe The Image Properly")
Example Request:
curl -X POST https://yourdomain.com/image.php \
-H "Content-Type: application/json" \
-d '{
"imageBase64": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE...",
"mimeType": "image/jpeg",
"prompt": "Describe the objects in this image"
}'
Success Response:
{
"success": true,
"analysis": "The image shows a sunny beach with palm trees, clear blue water, and a small boat."
}
Error Response:
{
"success": false,
"error": "Image Utils API Dead Bro",
"details": "Invalid JSON input"
}
You can generate Base64 strings using:
Online Tools:
Command Line:
base64 -i image.jpg
JavaScript:
const file = document.querySelector('input[type="file"]').files[0];
const reader = new FileReader();
reader.onloadend = () => {
const base64String = reader.result.split(',')[1];
console.log(base64String);
};
reader.readAsDataURL(file);
The API provides specific error codes and messages:
- 400 Bad Request: Invalid JSON, missing image data, or incorrect Content-Type
- 405 Method Not Allowed: Unsupported HTTP method
- 500 Internal Server Error: Issues with Gemini API or server configuration
- Maximum Image Size: 5MB
- Supported Formats: JPEG, PNG, WEBP only
- Rate Limits: Subject to Google Gemini API limits and hosting provider restrictions
- Security: API key should be properly secured in production environments
We welcome contributions to improve the Image Info API:
- Fork the repository: github.com/TheSmartDevs/Image-Info-API
- Create a branch for your feature or fix
- Submit a pull request with clear description
Please follow the existing code style and include tests where possible.
For questions or support:
- Open an issue on GitHub
- Contact @TheSmartDev or @nkka404
Powered by @TheSmartDev and @nkka404