View Source Imgex (imgex v0.4.0)
Provides functions to generate secure Imgix URLs.
Summary
Functions
Provides configured source information when it's not passed explicitly to
url/3 or proxy_url/3.
Generates a secure Imgix URL from a Web Proxy source given
Generates custom srcset attributes for Imgix URLs, pre-signed with the
source's secure token (if configured). These are useful for responsive
images at a variety of screen sizes or pixel densities.
Generates a secure Imgix URL given
Functions
Provides configured source information when it's not passed explicitly to
url/3 or proxy_url/3.
Generates a secure Imgix URL from a Web Proxy source given:
path- The full public image URL.params- (optional) A map containing Imgix API parameters used to manipulate the image.source- (optional) A map containing Imgix source information::token- The secure token used to sign API requests.:domain- The Imgix source domain.
Examples
iex> Imgex.proxy_url "http://avatars.com/john-smith.png"
"https://my-social-network.imgix.net/http%3A%2F%2Favatars.com%2Fjohn-smith.png?s=493a52f008c91416351f8b33d4883135"
iex> Imgex.proxy_url "http://avatars.com/john-smith.png", %{w: 400, h: 300}
"https://my-social-network.imgix.net/http%3A%2F%2Favatars.com%2Fjohn-smith.png?h=300&w=400&s=a201fe1a3caef4944dcb40f6ce99e746"
Generates custom srcset attributes for Imgix URLs, pre-signed with the
source's secure token (if configured). These are useful for responsive
images at a variety of screen sizes or pixel densities.
By default, the srcset generated will allow for responsive size switching
by building a list of image-width mappings. This default list of image
width mappings covers a wide range of 31 different widths from 100px to
8192px. This default results in quite a long srcset attribute, though, so
it is preferable to instead give more specific size guidance by specifying
either:
- a width, OR
- a height + aspect ratio
When these params are provided, the returned srcset will cover 5
different pixel densities (1x-5x).
Arguments
path- The URL path to the image.params- (optional) A map containing Imgix API parameters used to manipulate the image.source- (optional) A map containing Imgix source information::token- The secure token used to sign API requests.:domain- The Imgix source domain.
Examples
iex> Imgex.srcset("/images/lulu.jpg", %{w: 100})
"https://my-social-network.imgix.net/images/lulu.jpg?dpr=1&w=100&s=9bd210f344a0f65032951a9cf171c40e 1x,
https://my-social-network.imgix.net/images/lulu.jpg?dpr=2&w=100&s=33520b8f84fa72afa28539d66fb2734f 2x,
https://my-social-network.imgix.net/images/lulu.jpg?dpr=3&w=100&s=97d0f1731b4c8d8dd609424dfca2eab5 3x,
https://my-social-network.imgix.net/images/lulu.jpg?dpr=4&w=100&s=b96a02e08eeb50df5a75223c998e46f5 4x,
https://my-social-network.imgix.net/images/lulu.jpg?dpr=5&w=100&s=9ba1ab37db9f09283d9194223fbafb2f 5x"
iex> Imgex.srcset("/images/lulu.jpg", ar: "3:4", h: 500)
"https://my-social-network.imgix.net/images/lulu.jpg?dpr=1&ar=3%3A4&h=500&s=842a70d9c7ead7417b4a8056f45a88b3 1x,
https://my-social-network.imgix.net/images/lulu.jpg?dpr=2&ar=3%3A4&h=500&s=7cce91f2cd0d2bd1d252ca241523c09b 2x,
https://my-social-network.imgix.net/images/lulu.jpg?dpr=3&ar=3%3A4&h=500&s=509e0045d21a08324811d2db978c874c 3x,
https://my-social-network.imgix.net/images/lulu.jpg?dpr=4&ar=3%3A4&h=500&s=cc5790442b6185768435a48a44e040c9 4x,
https://my-social-network.imgix.net/images/lulu.jpg?dpr=5&ar=3%3A4&h=500&s=cf724f11656961377da13f8608c60b4a 5x"
Generates a secure Imgix URL given:
path- The URL path to the image.params- (optional) A map containing Imgix API parameters used to manipulate the image.source- (optional) A map containing Imgix source information::token- The secure token used to sign API requests.:domain- The Imgix source domain.
Examples
iex> Imgex.url "/images/jets.png"
"https://my-social-network.imgix.net/images/jets.png?s=7c6a3ef8679f4965f5aaecb66547fa61"
iex> Imgex.url "/images/jets.png", %{con: 10}, %{domain: "https://cannonball.imgix.net", token: "xxx187xxx"}
"https://cannonball.imgix.net/images/jets.png?con=10&s=d982f04bbca4d819971496524aa5f95a"