This is a simple kitten image resizer API built with Go and the Gin framework. It provides endpoints to serve images in color or grayscale, resized to the specified dimensions. The images are served from a specified directory, and the API supports both color and grayscale transformations.
- Go 1.18 or later
- Gin Framework
- nfnt/resize
-
Clone the repository:
git clone https://github.com/dhruvsangamwar/placekittens.git cd palcekittens
-
Install dependencies:
go mod tidy
-
Set up the image directory:
Ensure you have a directory named
public
(or change the path in theGetRandomImage
function) with images that will be used by the API. -
Modify paths if necessary:
The API expects images to be located in
../public
. Adjust the paths in theGetRandomImage
function if your directory structure is different.
-
Launch the server:
go run main.go
-
Access the API:
- The server will start on
localhost:8080
.
- The server will start on
-
Home Page
GET /
Renders an HTML page located at
./static/index.html
. -
Resize Image (Color)
GET /:width/:height
Returns a color image resized to the specified width and height.
Parameters:
width
: Desired width of the image.height
: Desired height of the image.
Example:
curl http://localhost:8080/300/200
-
Resize Image (Grayscale)
GET /g/:width/:height
Returns a grayscale image resized to the specified width and height.
Parameters:
width
: Desired width of the image.height
: Desired height of the image.
Example:
curl http://localhost:8080/g/300/200
-
Invalid Dimensions:
If the width or height provided is not a valid integer, a
400 Bad Request
error will be returned with a message indicating the error. -
File Access Errors:
If there are issues accessing or decoding images, a
500 Internal Server Error
will be returned.
This project is licensed under the MIT License - see the LICENSE file for details.