This project is an image manipulation API built using GoFiber and nfnt/resize for resizing and cropping images. The API allows you to resize or crop an image by specifying the dimensions and the image URL.
- Resize Images: Resize an image by specifying the desired width and height.
- Crop Images: Crop an image by providing the crop width, height, and starting coordinates (
x
andy
). - Supported Formats: PNG and JPEG image formats are supported.
- Clone the repository:
git clone https://github.com/<your-username>/<your-repo>.git
cd <your-repo>
- Install the dependencies:
go mod tidy
- Run the server:
go run main.go
You can use this API to resize or crop images by sending HTTP GET requests with the appropriate query parameters.
To resize an image
image
(required): The URL of the image to resize.width
(required): The desired width of the image.height
(required): The desired height of the image.mode
(optional): If set to"resize"
, the image will be resized (default behavior if mode is omitted).
Example Request:
http://localhost:3000/?image=https://example.com/image.png&width=200&height=100&mode=resize
To crop an image, make a GET request with the following query parameters:
image
(required): The URL of the image to crop.width
(required): The width of the cropped area.height
(required): The height of the cropped area.x
(required): The x-coordinate of the top-left corner where cropping should start.y
(required): The y-coordinate of the top-left corner where cropping should start.mode
(required): Set to"crop"
for cropping mode.
Example Request:
http://localhost:3000/?image=https://example.com/image.png&width=100&height=100&x=50&y=50&mode=crop
The API supports both PNG and JPEG formats. Based on the input image format, the API will return the resized/cropped image in the same format.
The API will return appropriate error messages for invalid or missing parameters:
- 400 Bad Request: Returned when the query parameters (e.g., width, height, etc.) are invalid.
- 502 Bad Gateway: Returned when the image URL is invalid or inaccessible.
- 415 Unsupported Media Type: Returned if the image format is not supported.
This project uses the following Go packages:
- GoFiber: A fast HTTP web framework for building web applications in Go.
- nfnt/resize: A library for resizing images in Go.
- image/jpeg: The standard Go library for working with JPEG image formats.
- image/png: The standard Go library for working with PNG image formats.
This project is licensed under the MIT License. See the LICENSE file for details.