Storehouse.Renderer.Imgproxy (Storehouse v0.2.0)

Copy Markdown View Source

The URLs of variants imgproxy renders (Storehouse.Renderer): signed, so only the presets' sizes are ever rendered, and the same every time, for a CDN in front of it to keep. The app renders nothing, and stores nothing.

config :storehouse, Storehouse.Variants,
  renderer:
    {Storehouse.Renderer.Imgproxy,
     url: "https://images.example.com",
     key: System.fetch_env!("IMGPROXY_KEY"),
     salt: System.fetch_env!("IMGPROXY_SALT"),
     source: "s3://my-bucket/"},
  presets: [photo: [widths: [640, 1280, 1920], format: [:webp, :original]]]

A preset is written as imgproxy's processing options:

  • a width alone is w:<width>; a box, rs:fit:<width>:<height>, or rs:fill:<width>:<height> with fit: :cover and its gravity (g:ce, g:sm for :attention and :entropy, g:fp:<x>:<y>);
  • q:<quality>, when the preset gives one;
  • f:<format> for one format; none for :original, or for several, which imgproxy chooses itself by Accept (with IMGPROXY_AUTO_WEBP or IMGPROXY_AUTO_AVIF on);
  • scp:0 for profile: :keep, sm:0 for metadata: :all (imgproxy strips metadata by default), a background as bg:<hex>;
  • then the preset's options: [imgproxy: "…"], as they are: "sh:0.3/fq:webp:86:jpeg:90".

imgproxy never enlarges an image unless it is told to.

Options

  • :url - imgproxy's address (or the CDN's in front of it). Required.
  • :key and :salt - imgproxy's, in hex (IMGPROXY_KEY, IMGPROXY_SALT). Without them, URLs are unsigned (/insecure/): for development only, as anyone could ask for any size.
  • :source - where imgproxy reads the original: a prefix the key is put after ("s3://my-bucket/", "local:///"), or a function of the file that gives its address. The default is the store's URL of the file (Storehouse.url/2).
  • :extension - true ends the URL with the format's extension (…/<source>.webp) in place of f:. The default is false.

Its own addresses

For URLs of another shape (a CDN's Worker that signs them itself), signed_path/2 gives the path imgproxy is asked, and a renderer of the app's own builds the rest.

Summary

Functions

The path of variant for imgproxy, not yet signed: /<processing options>/<encoded source>.

path signed with the options' :key and :salt: "/<signature><path>", as imgproxy checks it (HMAC-SHA256 of the salt and the path), or "/insecure<path>" without them.

Functions

path(variant, file, opts)

The path of variant for imgproxy, not yet signed: /<processing options>/<encoded source>.

signed_path(path, opts)

@spec signed_path(String.t(), keyword()) :: String.t()

path signed with the options' :key and :salt: "/<signature><path>", as imgproxy checks it (HMAC-SHA256 of the salt and the path), or "/insecure<path>" without them.