84 lines
2.5 KiB
Markdown
84 lines
2.5 KiB
Markdown
A simple image uploader over SSH for static image hosting.
|
|
|
|
Normalize, strip, and upload images via scp.
|
|
|
|
Usage: `imup [ -h | --help ] [SRC ...]`
|
|
|
|
SRC may be a path or url to an image file, or a special value.
|
|
|
|
* '-' read from stdin.
|
|
* '+' read from the system clipboard.
|
|
|
|
If no SRC is provided, read from the system clipboard.
|
|
|
|
## Sample Usage
|
|
|
|
- From clipboard
|
|
```zsh
|
|
$ imup
|
|
https://i.allemangd.dev/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.webp (<clipboard>)
|
|
```
|
|
|
|
- From file or URL
|
|
```zsh
|
|
$ imup image.png ./image.jpeg 'https://example.com/image.webp'
|
|
https://i.allemangd.dev/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.webp (image.png)
|
|
https://i.allemangd.dev/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.webp (./image.jpeg)
|
|
https://i.allemangd.dev/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.webp (https://example.com/image.webp)
|
|
```
|
|
|
|
- From stdin
|
|
```zsh
|
|
$ convert image.png -resize 50% - | imup -
|
|
https://i.allemangd.dev/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.webp (<stdin>)
|
|
```
|
|
|
|
## Installation and setup.
|
|
|
|
This assumes you already have some hosted static files and ssh configured with write permissions to that directory. Images are copied to the host via `scp`. Thus authentication is deferred to other systems like VPN and SSH, and hosting is deferred to static web servers like nginx. This tool is only a convenience to normalize/strip image data and upload the files.
|
|
|
|
The client depends on `imagemagick`, `scp`, and `xclip`. The host only needs to serve the static files.
|
|
|
|
```zsh
|
|
apt install imagemagick ssh xclip
|
|
```
|
|
|
|
Copy `imup` to your `~/.zfunc` or somewhere else on your zsh `fpath`. Add the configuration to your `~/.zshrc`:
|
|
|
|
```
|
|
autoload -Uz imup
|
|
export IMUP_SCP_DIR="..." # The target location.
|
|
export IMUP_URL="..." # The base url to access images.
|
|
```
|
|
|
|
For example, on my host `allemangd.dev` I have the following nginx static server:
|
|
|
|
```
|
|
# nginx config
|
|
server {
|
|
listen 80;
|
|
# (ssl settings omitted)
|
|
|
|
server_name i.allemangd.dev;
|
|
|
|
location / {
|
|
root /var/www/i.allemangd.dev/;
|
|
autoindex on;
|
|
}
|
|
}
|
|
```
|
|
|
|
I've granted write permissions to `/var/www/i.allemangd.dev` to my ssh user, and configured an ssh host for that user.
|
|
|
|
```
|
|
# ssh config
|
|
Host imup-host
|
|
HostName ...
|
|
User ...
|
|
IdentifyFile ...
|
|
```
|
|
|
|
Then I set `IMUP_SCP_DIR="imup-host:/var/www/i.allemangd.dev` and `IMUP_URL=https://i.allemangd.dev` in my `~/.zshrc`.
|
|
|
|
The development environment in `mise.toml` uses the local directory `./images/` for both of these to avoid hosting/authentication requirements while testing.
|