Flip Image
Mirror an image horizontally, vertically, or both to create a flipped version.
POST
/api/image/flip
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
file | File | Yes | The image file to flip. Supported formats: JPEG, PNG, WebP, BMP, TIFF, GIF. |
mode | String | Yes | Flip mode. Allowed values: "horizontal", "vertical". |
quality | Integer | No | The quality of the output image for lossy formats (JPEG, WebP). Range: 1-100. Default: 90 . |
Response
Returns the flipped image in the specified or original format.
Example Request
// example.sh
curl -X POST "https://oyyi.xyz/api/image/flip" -H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "file=@image.jpg" \
-F "mode=horizontal" \
--output flipped.jpg
Example with Python
// flip.py
import requests
url = "https://oyyi.xyz/api/image/flip"
files = {
'file': open('image.jpg', 'rb')
}
data = {
'mode': 'horizontal'
}
response = requests.post(url, files=files, data=data)
# Save the flipped image
with open('flipped.jpg', 'wb') as f:
f.write(response.content)
Example with JavaScript
// flip.js
// Using fetch API
const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('direction', 'horizontal');
fetch('https://oyyi.xyz/api/image/flip', {
method: 'POST',
body: formData
})
.then(response => response.blob())
.then(blob => {
// Create a URL for the blob
const url = URL.createObjectURL(blob);
// Create a link to download the image
const a = document.createElement('a');
a.href = url;
a.download = 'flipped.jpg';
a.click();
// Clean up by revoking the URL
URL.revokeObjectURL(url);
})
.catch(error => console.error('Error:', error));
Flip Directions
Horizontal
Flips the image from left to right, creating a mirror image along the vertical axis. This is the most common type of flip.
Vertical
Flips the image from top to bottom, creating a mirror image along the horizontal axis. This inverts the image upside down.
Both
Flips the image both horizontally and vertically, effectively rotating it 180 degrees. This creates a mirror image along both axes.
How It Works
The flip endpoint mirrors an image along one or both axes:
- Image Loading: The uploaded image is loaded into memory.
- Flip Operation: Depending on the direction parameter:
- Horizontal: Each pixel's x-coordinate is mirrored across the vertical center line of the image.
- Vertical: Each pixel's y-coordinate is mirrored across the horizontal center line of the image.
- Both: Both horizontal and vertical flips are applied, effectively rotating the image 180 degrees.
- Format Conversion: If an output_format is specified, the flipped image is converted to that format.
- Quality Setting: For lossy formats (JPEG, WebP), the specified quality level is applied.
The result is an image that has been mirrored according to the specified direction.
Visual Representation
Flip operations visualized:
Original: Horizontal Flip: Vertical Flip: Both: +---+---+ +---+---+ +---+---+ +---+---+ | A | B | | B | A | | C | D | | D | C | +---+---+ → +---+---+ → +---+---+ → +---+---+ | C | D | | D | C | | A | B | | B | A | +---+---+ +---+---+ +---+---+ +---+---+
Error Responses
Status Code | Description |
---|---|
400 | Bad request. Missing required parameters, invalid direction value, invalid output_format, invalid quality value, or invalid file format. |
413 | Payload too large. The file size exceeds the maximum allowed limit. |
500 | Internal server error. Something went wrong on the server. |
Notes
- Flipping is a lossless transformation that preserves the original image quality.
- The dimensions of the image remain unchanged after flipping.
- Flipping is often used to correct mirror images or to create symmetrical compositions.
- For images with text or recognizable elements (like faces), horizontal flipping will make the text appear backward and may look unnatural.
- For animated GIFs, all frames will be flipped if the output format is also GIF.
- The maximum file size allowed is 50MB.
- This operation preserves the alpha channel (transparency) if present in the original image and the output format supports it.
Use Cases
- Correcting mirror images from front-facing cameras
- Creating symmetrical compositions for design purposes
- Adjusting the direction of elements in an image for layout requirements
- Creating variations of logos or design elements
- Correcting scanned images that were placed incorrectly on the scanner
- Creating reflection effects when combined with other image processing operations
- Implementing image editing functionality in applications
- Creating before/after comparisons with mirrored images