by Lazy Sloth
Extract Metadata from Images
import logging
from fastapi import FastAPI, File, UploadFile, HTTPException
from fastapi.responses import HTMLResponse
from pydantic import BaseModel
import os
from PIL import Image
from io import BytesIO
from abilities import upload_file_to_storage
import json
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = FastAPI()
class ImageMetaData(BaseModel):
format: str
mode: str
size: tuple
info: dict
def extract_image_metadata(image_bytes):
Created: | Last Updated:
Introduction to the Image Metadata Extractor Template
Welcome to the Image Metadata Extractor template! This template is designed to help you build a web application that allows users to upload images and extract metadata such as the image format, mode, size, and additional information. The extracted metadata is then provided to the user as a downloadable JSON file. This template is perfect for builders who want to create an application without worrying about the complexities of deployment and environment setup.
Getting Started
To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code.
Test: Deploying the App
Once you have the template loaded, press the "Test" button. This will initiate the deployment of your app and launch the Lazy CLI. The deployment process is handled entirely by Lazy, so you can sit back and relax while your app is being set up.
Using the App
After the deployment is complete, Lazy will provide you with a dedicated server link to access your new web application. Navigate to this link to see the main page of your Image Metadata Extractor app. Here's how to use the interface:
- On the main page, you will see a form where you can upload an image file.
- Select an image file from your device by clicking on the "Choose File" button. Make sure it's an image file, as the app is designed to work with images only.
- After selecting the file, click on the "Extract Metadata" button to upload the image and process it.
- If the image is processed successfully, a "Download Metadata" button will appear. Click on this button to download the metadata as a JSON file.
If you encounter any errors or the file you uploaded is not an image, the app will alert you with an appropriate message.
Integrating the App
If you wish to integrate this app into another service or frontend, you can use the server link provided by Lazy to make API calls to the /upload_image
endpoint. Here's a sample request you might use in your integration:
POST /upload_image
Content-Type: multipart/form-data
Include the image file in the body of the request as form data.
Here's a sample response you might receive:
{
"message": "Image metadata extraction completed",
"image_metadata": "{JSON string containing the metadata}"
}
Use this response to handle the extracted metadata in your external tool or service.
That's all there is to it! With just a few clicks, you can deploy and use the Image Metadata Extractor app on the Lazy platform, making it a breeze to add image metadata extraction functionality to your projects.