The backend of https://lorem.space lives here.
- Scan the directory & categorize the image resources (only JPEG for now)
- Provide HTTP API
- Resize the image resources
- Cache option to store the resized image as a file
$ go run main.go
$ go run main.go --dir="/IMAGE/DIRECTORY/PATH"
host: host:port for the HTTP server (string)dir: the path of image resources directory (string)cache: enable cache (store the result as files in .cache directory) (bool)cdn: CDN address to redirect to the cached file path, leave empty to write the file in the HTTP response (string)min-width: minimum supported width (integer)max-width: maximum supported width (integer)min-height: minimum supported height (integer)max-height: maximum supported height (integer)
To run built binary, visit the release page & download your OS build file. Unzip the downloaded file & make sure about the file execution permissions, then run the app with the arguments in the terminal:
- MacOS & Linux:
./lorem-server --host "127.0.0.1:8080" --dir "~/Pictures" - Windows:
lorem-server.exe -host "127.0.0.1:8080" -dir "C:\Users\USER\Pictures"
You can pull & run the public docker image from github package registry:
$ docker pull ghcr.io/manasky/lorem-server:latest
To run the container you must pass the app arguments via the .env file. To this, create a file named .env & set the options in uppercase & snake case format.
An example of .env file:
HOST=0.0.0.0:8080
DIR=/app/images
MIN_WIDTH=20
By this config, the app listens to port number 8080 on the host IP address and scan /app/images/ path (from the container) for the images and limit the width size to a minimum of 20 pixels.
Your images directory must link to the container, to this you can use -v arguments while running the container.
$ docker run --env-file=./.env -p 8080:8080 -v ~/Pictures:/app/images ghcr.io/manasky/lorem-server:latest
--env-filesets the application environment variables path. here.envfile exists in the current path.-p 8080:8080sets up a port forward. the application container will listen to the8080port (set in the .env file asHOST). this flag maps the container's port8080to port8080on the host (here, your localhost).~/Pictures:/app/imagessets up a bindmount volume that links the directory/app/imagesfrom inside the app container to the directory~/Pictureson the host machine (here, your system). The app image directory is set in the.envfile as/app/images, so here the~/Picturesis mounted to that.
After container running, the app will scan /app/images which is mounted to the directory ~/Pictures of your system & serves the HTTP server on 127.0.0.1:8080. Visit 127.0.0.1:8080/image for start.