Skip to content

TheSmartDevs/Image-Info-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Image Info API

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.

Stars Forks License Language

Repository: github.com/TheSmartDevs/Image-Info-API

Features

  • 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

Prerequisites

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

Setup Instructions

Follow these steps to host the Image Info API on your domain:

  1. 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';)
  2. 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)
  3. Verify the Installation

    • Access the API at https://yourdomain.com/image.php
    • Use the GET endpoint to confirm it's working
  4. 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

API Usage

The API provides two endpoints:

1. Health Check (GET)

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"
  }
}

2. Image Analysis (POST)

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"
}

Converting Images to Base64

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);

Error Handling

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

Limitations

  • 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

Contributing

We welcome contributions to improve the Image Info API:

  1. Fork the repository: github.com/TheSmartDevs/Image-Info-API
  2. Create a branch for your feature or fix
  3. Submit a pull request with clear description

Please follow the existing code style and include tests where possible.

Contact

For questions or support:


Powered by @TheSmartDev and @nkka404

About

Image Info API Is The Best AI Based Image Info Extractor API By @TheSmartDevs & @nyeinkokoaung404

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages