5 Ways to Automate Image Processing with AI APIs
Manual image editing doesn't scale. Whether you're running an e-commerce store with 10,000 product photos or building a content platform that handles user uploads, you need automated image processing that just works.
Modern AI APIs have replaced fragile OpenCV pipelines and expensive Photoshop actions. Here are five image processing tasks you can fully automate today using the PixelAPI Python SDK — each with real code you can drop into your project.
pip install pixelapi
from pixelapi import PixelAPI
client = PixelAPI() # reads PIXELAPI_KEY from env
1 Background Removal
The most common image processing task in e-commerce, design tools, and social media apps. AI-powered background removal handles hair, transparency, complex edges, and even semi-transparent objects like glass — all in under a second.
import os
from pathlib import Path
input_dir = Path("product_photos/")
output_dir = Path("product_photos_clean/")
output_dir.mkdir(exist_ok=True)
for img_path in input_dir.glob("*.jpg"):
result = client.image.remove_background(
image=str(img_path),
output_format="png",
refine_edges=True # extra edge refinement
)
result.save(output_dir / f"{img_path.stem}.png")
print(f"✓ {img_path.name} → background removed")
refine_edges=True for product photography — it adds a slight feathering that prevents harsh cutout artifacts. For flat graphic assets, leave it off for pixel-perfect edges.
2 Image Upscaling
Low-resolution thumbnails, user-uploaded images, and legacy assets all need upscaling. AI upscaling doesn't just enlarge — it reconstructs detail, sharpens textures, and removes compression artifacts. The result looks like a natively high-resolution image.
# Upscale a single image
result = client.image.upscale(
image="low_res_hero.jpg",
scale=4, # 2x or 4x
model="real-esrgan",
denoise_strength=0.5 # 0.0-1.0, helps with JPEG artifacts
)
result.save("hero_4x.png")
print(f"Upscaled to {result.width}x{result.height}")
Python — Batch
# Batch upscale with async for speed
import asyncio
from pixelapi import AsyncPixelAPI
async def upscale_batch(image_paths, scale=4):
async_client = AsyncPixelAPI()
tasks = [
async_client.image.upscale(image=str(p), scale=scale)
for p in image_paths
]
results = await asyncio.gather(*tasks)
for path, result in zip(image_paths, results):
result.save(f"upscaled/{path.stem}_{scale}x.png")
return len(results)
paths = list(Path("thumbnails/").glob("*.jpg"))
count = asyncio.run(upscale_batch(paths))
print(f"Upscaled {count} images")
3 Face Restoration
Old family photos, low-quality video frames, compressed social media images — face restoration brings faces back to life. It reconstructs facial features, sharpens skin texture, and corrects artifacts while keeping the person recognizable.
# Restore faces in a photo
result = client.image.restore_face(
image="old_family_photo.jpg",
model="codeformer",
fidelity=0.7, # 0.0 = max quality, 1.0 = max fidelity to original
upscale=2 # optionally upscale while restoring
)
result.save("family_restored.png")
# Works great in a pipeline with upscaling
upscaled = client.image.upscale(image=result.image_bytes, scale=2)
upscaled.save("family_restored_4x.png")
0.7 and adjust.
4 Object Removal (Inpainting)
Remove unwanted objects, watermarks, people in the background, or blemishes — and the AI fills in the gap with contextually appropriate content. No manual clone-stamping needed.
# Remove an object using a mask
result = client.image.inpaint(
image="architecture_photo.jpg",
mask="mask.png", # white = remove, black = keep
prompt="clean stone pavement, same lighting and perspective",
model="flux-schnell",
strength=0.85
)
result.save("architecture_clean.png")
Python — Auto-detect & remove
# Or describe what to remove — no mask needed
result = client.image.remove_object(
image="architecture_photo.jpg",
object_prompt="trash can in the foreground",
fill_prompt="stone pavement matching surroundings"
)
result.save("architecture_clean.png")
The mask-free approach uses an internal segmentation model to identify the object before inpainting. For production use with consistent results, provide explicit masks.
5 Style Transfer
Transform photos into artistic styles — watercolor, oil painting, anime, pixel art, pencil sketch — while preserving composition and structure. Perfect for content variation, social media, and creative tools.
# Apply style transfer
result = client.image.style_transfer(
image="city_street.jpg",
style="ghibli-watercolor", # preset style
strength=0.75, # how much to stylize (0.0-1.0)
preserve_structure=True # keep composition intact
)
result.save("city_ghibli.png")
Python — Custom style from reference
# Use a reference image as the style source
result = client.image.style_transfer(
image="city_street.jpg",
style_image="van_gogh_starry_night.jpg", # reference
strength=0.6,
preserve_structure=True
)
result.save("city_vangogh.png")
Available preset styles include: ghibli-watercolor, oil-painting, anime, pixel-art, pencil-sketch, comic-book, low-poly, and cyberpunk. Or use any image as a style reference.
Putting It All Together: A Complete Pipeline
Here's a real-world example — an e-commerce image pipeline that processes raw product photos into web-ready assets:
from pixelapi import PixelAPI
from pathlib import Path
client = PixelAPI()
def process_product_image(input_path: str, output_dir: str = "processed"):
"""Full product image pipeline: remove BG → restore → upscale"""
out = Path(output_dir)
out.mkdir(exist_ok=True)
stem = Path(input_path).stem
# Step 1: Remove background
no_bg = client.image.remove_background(
image=input_path,
output_format="png",
refine_edges=True
)
# Step 2: Face restoration (if applicable — e.g. model wearing product)
restored = client.image.restore_face(
image=no_bg.image_bytes,
fidelity=0.8
)
# Step 3: Upscale to 2x for retina displays
final = client.image.upscale(
image=restored.image_bytes,
scale=2
)
final.save(out / f"{stem}_final.png")
print(f"✓ {stem}: {final.width}x{final.height}")
return final
# Process all product photos
for photo in Path("raw_products/").glob("*.jpg"):
process_product_image(str(photo))
Further Reading
- 📖 PixelAPI Documentation — complete reference for every endpoint
- 🎨 AI Editor — test these features interactively in the browser
- 🚀 Generate AI Images via API — our complete generation tutorial
- 🏗️ Build an AI Image SaaS — turn these capabilities into a product
Automate Your Image Pipeline
100 free API calls per day. Process thousands of images with a few lines of Python.
Get Started Free →