{
  "openapi": "3.0.3",
  "info": {
    "title": "Image Toolkit",
    "description": "Resize, convert, compress, and crop images (JPEG/PNG/WebP/AVIF) from a URL or base64 — fast, no storage.",
    "version": "1.0.0"
  },
  "components": {
    "schemas": {}
  },
  "paths": {
    "/resize": {
      "post": {
        "summary": "Resize an image",
        "tags": [
          "Image"
        ],
        "description": "Resize an image to width and/or height with a fit mode (cover, contain, fill, inside, outside). Returns the image bytes (default) or JSON with base64.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "Public image URL",
                    "example": "https://picsum.photos/800"
                  },
                  "base64": {
                    "type": "string",
                    "description": "Base64-encoded image (data URI ok)"
                  },
                  "output": {
                    "type": "string",
                    "enum": [
                      "binary",
                      "base64"
                    ],
                    "default": "binary",
                    "description": "Return the image bytes or JSON with base64"
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "jpeg",
                      "png",
                      "webp",
                      "avif"
                    ],
                    "description": "Output format (default: keep input)"
                  },
                  "quality": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "default": 80,
                    "description": "Output quality (lossy formats)"
                  },
                  "width": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 5000,
                    "example": 400
                  },
                  "height": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 5000,
                    "example": 400
                  },
                  "fit": {
                    "type": "string",
                    "enum": [
                      "cover",
                      "contain",
                      "fill",
                      "inside",
                      "outside"
                    ],
                    "default": "cover"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Bad request",
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "502": {
            "description": "Could not load the image",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Could not load the image",
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/convert": {
      "post": {
        "summary": "Convert an image to another format",
        "tags": [
          "Image"
        ],
        "description": "Convert between JPEG, PNG, WebP, and AVIF. Returns the image bytes (default) or JSON with base64.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "format"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "Public image URL",
                    "example": "https://picsum.photos/800"
                  },
                  "base64": {
                    "type": "string",
                    "description": "Base64-encoded image (data URI ok)"
                  },
                  "output": {
                    "type": "string",
                    "enum": [
                      "binary",
                      "base64"
                    ],
                    "default": "binary",
                    "description": "Return the image bytes or JSON with base64"
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "jpeg",
                      "png",
                      "webp",
                      "avif"
                    ],
                    "description": "Output format (default: keep input)"
                  },
                  "quality": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "default": 80,
                    "description": "Output quality (lossy formats)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Bad request",
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "502": {
            "description": "Could not load the image",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Could not load the image",
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/compress": {
      "post": {
        "summary": "Compress an image",
        "tags": [
          "Image"
        ],
        "description": "Re-encode an image at a target quality to shrink its size. Defaults to WebP for the best compression; pass format to keep or choose another.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "Public image URL",
                    "example": "https://picsum.photos/800"
                  },
                  "base64": {
                    "type": "string",
                    "description": "Base64-encoded image (data URI ok)"
                  },
                  "output": {
                    "type": "string",
                    "enum": [
                      "binary",
                      "base64"
                    ],
                    "default": "binary",
                    "description": "Return the image bytes or JSON with base64"
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "jpeg",
                      "png",
                      "webp",
                      "avif"
                    ],
                    "description": "Output format (default: keep input)"
                  },
                  "quality": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "default": 80,
                    "description": "Output quality (lossy formats)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Bad request",
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "502": {
            "description": "Could not load the image",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Could not load the image",
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/crop": {
      "post": {
        "summary": "Crop a region of an image",
        "tags": [
          "Image"
        ],
        "description": "Extract a rectangular region (left, top, width, height) from the image.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "left",
                  "top",
                  "width",
                  "height"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "Public image URL",
                    "example": "https://picsum.photos/800"
                  },
                  "base64": {
                    "type": "string",
                    "description": "Base64-encoded image (data URI ok)"
                  },
                  "output": {
                    "type": "string",
                    "enum": [
                      "binary",
                      "base64"
                    ],
                    "default": "binary",
                    "description": "Return the image bytes or JSON with base64"
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "jpeg",
                      "png",
                      "webp",
                      "avif"
                    ],
                    "description": "Output format (default: keep input)"
                  },
                  "quality": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "default": 80,
                    "description": "Output quality (lossy formats)"
                  },
                  "left": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 20000,
                    "example": 0
                  },
                  "top": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 20000,
                    "example": 0
                  },
                  "width": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 20000,
                    "example": 300
                  },
                  "height": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 20000,
                    "example": 300
                  }
                }
              }
            }
          }
        },
        "responses": {
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Bad request",
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "502": {
            "description": "Could not load the image",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Could not load the image",
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/info": {
      "post": {
        "summary": "Get image metadata",
        "tags": [
          "Image"
        ],
        "description": "Return format, dimensions, channels, color space, alpha, orientation, and byte size — without re-encoding.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "Public image URL",
                    "example": "https://picsum.photos/800"
                  },
                  "base64": {
                    "type": "string",
                    "description": "Base64-encoded image (data URI ok)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Default Response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "format": {
                      "type": "string",
                      "nullable": true
                    },
                    "width": {
                      "type": "integer",
                      "nullable": true
                    },
                    "height": {
                      "type": "integer",
                      "nullable": true
                    },
                    "channels": {
                      "type": "integer",
                      "nullable": true
                    },
                    "space": {
                      "type": "string",
                      "nullable": true
                    },
                    "hasAlpha": {
                      "type": "boolean"
                    },
                    "orientation": {
                      "type": "integer",
                      "nullable": true
                    },
                    "bytes": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Bad request",
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "502": {
            "description": "Could not load the image",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Could not load the image",
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "servers": [
    {
      "url": "https://web-toolbox-api-production.up.railway.app/image",
      "description": "Production"
    }
  ]
}