Skip to content

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.

License

Notifications You must be signed in to change notification settings

KonyD/image-manipulation-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Resizer & Cropper API

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.

Features

  • 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 and y).
  • Supported Formats: PNG and JPEG image formats are supported.

Installation

  1. Clone the repository:
git clone https://github.com/<your-username>/<your-repo>.git
cd <your-repo>
  1. Install the dependencies:
go mod tidy
  1. Run the server:
go run main.go

Usage

You can use this API to resize or crop images by sending HTTP GET requests with the appropriate query parameters.

Resizing an Image

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

Cropping an Image

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

Supported Formats

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.

Error Handling

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.

Dependencies

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.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages