Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xaionaro-go/picapi
An HTTP server that accept an URL (to a JPEG image) and returns a resized JPEG image (like `width=100&height=100&url=....`)
https://github.com/xaionaro-go/picapi
100krps cache fasthttp golang graphicsmagick-wrapper high-performance http-server interview-task jpeg opencv proxy resize-images service stupid
Last synced: 6 days ago
JSON representation
An HTTP server that accept an URL (to a JPEG image) and returns a resized JPEG image (like `width=100&height=100&url=....`)
- Host: GitHub
- URL: https://github.com/xaionaro-go/picapi
- Owner: xaionaro-go
- License: lgpl-3.0
- Created: 2019-09-04T20:05:26.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-07T07:59:20.000Z (about 5 years ago)
- Last Synced: 2024-06-20T08:19:15.075Z (5 months ago)
- Topics: 100krps, cache, fasthttp, golang, graphicsmagick-wrapper, high-performance, http-server, interview-task, jpeg, opencv, proxy, resize-images, service, stupid
- Language: Go
- Homepage:
- Size: 1.73 MB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Coverage Status](https://coveralls.io/repos/github/xaionaro-go/picapi/badge.svg?branch=master)](https://coveralls.io/github/xaionaro-go/picapi?branch=master)
# Introduction
"PicAPI" is an HTTP-server which implements a method to download a JPEG image and resize it.
# API
### `GET /resize`
| GET-parameter | description | required? |
| -------------:|:----------- | --------- |
| url | An URL to download the image | Y |
| width | resulting width (in pixels) | Y |
| height | resulting height (in pixels) | Y |#### Response
A JPEG image will be returned as the body.
If the response is returned from a cache then a header `X-Cached-Response` will also be returned.
#### cURL example:
```sh
curl -s --output /tmp/resized.jpg 'http://localhost:8486/resize?width=1230&height=200&url=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fc%2Fc7%2FJPS-sample.jpg'
```# Quick start
### Install build dependencies (Debian/Ubuntu)
```sh
sudo apt-get install libgraphicsmagick1-dev
```If you're unable to use external libraries (like `graphicsmagick`) then you can switch to a native implementation (`imageprocessorimaging` or `imageprocessornfntresize` instead of `imageprocessorgraphicsmagick`) in file `imageprocessor/image_processor.go`.
### Install
```sh
go get github.com/xaionaro-go/picapi/cmd/picapid
```### Run
```sh
PICAPI_LOGGING_LEVEL=debug $(go env GOPATH)/bin/picapid
```# Performance test
```sh
$(go env GOPATH)/bin/picapid &
$(go env GOPATH)/bin/gobench -u 'http://localhost:8486/resize?width=10&height=10&url=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fc%2Fc7%2FJPS-sample.jpg' -t 10
``````
Dispatching 100 clients
Waiting for results...Requests: 1077603 hits
Successful requests: 1077603 hits
Network failed: 0 hits
Bad requests failed (!2xx): 0 hits
Successful requests rate: 107760 hits/sec
Read throughput: 57007156 bytes/sec
Write throughput: 21339232 bytes/sec
Test time: 10 sec
``````
cpufreq-info | grep 'current policy' | head -1; echo; grep 'model name' /proc/cpuinfo | head -1current policy: frequency should be within 800 MHz and 3.70 GHz.
model name : Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz
```# Packages
* `imageprocessor` is a wrapper around different image manipulation tools (like imagemagick). Currently we use `graphicsmagick` as the backend.
* `httpserver` is a wrapper around an http router (currently we use `fasthttprouter`) and `imageprocessor` to serve incoming HTTP requests.
* `main` (`cmd/picapid`) is the entry-point/executable package.
* `config` is just a structure to configure the `main`.# Image Processors
You mean switch it to another image processor in file `imageprocessor/image_processor.go`. See [benchmarks](imageprocessor/README.md).