Imgdeflator is a small web server which handles POST requests with image attachments. It passes the received image through libvips to resize it to the specified width/height and then it stores it on S3 at the specified path.
It uses urlsign to validate the signature token in the request URL.
Kudos to DarthSim for writing imgproxy, which served as inspiration for this library!
go get github.com/Nitro/imgdeflatorJust run the executable. By default, it will bind to port 8080 and handle POST requests in the following format:
http://127.0.0.1:8080/base64_encoded_s3_location?width=1024&token=valid_token
or
http://127.0.0.1:8080/base64_encoded_s3_location?height=768&token=valid_token
Configuration is done using environment variables:
IMGDEFLATOR_LOGGING_LEVEL: The cut off level for log messages. Accepted values:debug,info,warn,error(defaultinfo).IMGDEFLATOR_MAX_UPLOAD_SIZE: The maximum allowed size for thePOSTed image (default5242880which is 5MB).IMGDEFLATOR_HTTP_PORT: The port to listen on for HTTP connections (default8080).IMGDEFLATOR_UPLOAD_TIMEOUT: The maximum allowed processing duration of the HTTP handler before sending an error to the user (default10s).IMGDEFLATOR_REQUEST_TIMEOUT: The maximum allowed duration of the entire HTTP request before sending an error to the user (default11s).IMGDEFLATOR_DEFAULT_S3_REGION: The default S3 region where to look for the S3 bucket of the received S3 location (defaulteu-central-1).IMGDEFLATOR_MAX_WIDTH: The maximumPOSTed image width (default4096).IMGDEFLATOR_MAX_HEIGHT: The maximumPOSTed image height (default4096).IMGDEFLATOR_URL_SIGNING_SECRET: A secret to use when validating signed URLs (default:deadbeef). Set it to empty string to disable signature validation.IMGDEFLATOR_SIGNING_BUCKET_SIZE: Theurlsigntime bucket size (default8h). It provides a3*bucketSizewindow of validity for each signature. See theurlsigndocumentation for more information.
- base64-encode a valid S3 location where you wish the image to be stored and append that to the imgdeflator URL:
> echo -n "s3://nitro-junk/imgdeflator.jpg" | base64 | tr '=' '\0' | xargs -I {} echo "http://127.0.0.1:8080/{}"
http://127.0.0.1:8080/czM6Ly9uaXRyby1qdW5rL2ltZ2RlZmxhdG9yLmpwZw- Instruct imgdeflator to shrink
resources/tweety.jpgto havewidth=1024and store it ats3://nitro-junk/imgdeflator.jpg:
> curl -v -H "Content-Type: image/jpeg" --data-binary "@resources/tweety.jpg" "http://127.0.0.1:8080/czM6Ly9uaXRyby1qdW5rL2ltZ2RlZmxhdG9yLmpwZw?width=1024"Copyright (c) 2019 Nitro Software.