cshum / imagor

Fast, secure image processing server and Go library, using libvips
Apache License 2.0
3.46k stars 137 forks source link

Default domain feature: Allow secondary domain #405

Open readtedium opened 1 year ago

readtedium commented 1 year ago

Bouncing off the great work done in #309, is it possible to add an override, or maybe an alternate? I think it might come in handy to have a default base URL but if you need to grab from a different domain than the default.

I mostly grab from one domain, but sometimes I grab from a second; currently the tool forces me to use long URLs for both, but I think adding the option for additional variables could be useful. One way I could see it working:

In .env:

HTTP_LOADER_BASE_URL=https://raw.githubusercontent.com/cshum/imagor/master
HTTP_LOADER_ALT_URL=https://img.youtube.com

First example (uses BASE_URL):

http://localhost:8000/unsafe/fit-in/200x150/filters:fill(yellow):watermark(testdata/gopher-front.png,repeat,bottom,0,40,40)/testdata/dancing-banana.gif

Second example (uses ALT_URL):

http://localhost:8000/unsafe/trim/700x394/alt_url/vi/jNQXAC9IVRw/hqdefault.jpg

Third example (with a watermark pulled from the base URL):

http://localhost:8000/unsafe/trim/700x394/filters:watermark(/testdata/dancing-banana.gif,0,0,25)/alt_url/vi/jNQXAC9IVRw/hqdefault.jpg

The one challenge I see is that if there’s a folder named ALT_URL it would override this, but I do think there’s probably a way to solve this, maybe by using a filter?

AlekseyArh commented 11 months ago

@readtedium Have you considered nginx proxy as a solution?

location /vi/ {
        proxy_pass https://img.youtube.com;
}

curl localhost/vi/jNQXAC9IVRw/hqdefault.jpg

readtedium commented 11 months ago

This required me to set up a separate NGINX proxy to reach my S3 bucket (this was a good guide), but once I did that, I found @AlekseyArh’s suggestion to be a good solve.

This idea may still be useful for those who don’t want to have to manage an additional NGINX proxy, though.