Libraries
imgix-csharp build
- Installation
- Usage
- Signed URLs
- Srcset Generation
- What is the
ixlib
param on every request? - Code of Conduct
Installation
The latest version of the library can be installed via NuGet:
Install-Package Imgix
Or you can clone this repository and build it.
Version 1.x
v1.x of the library can be installed via NuGet:
Install-Package Imgix-CSharp
Usage
You can start creating imgix URLs programmatically through UrlBuilder
instances. The URL builder can be reused to create URLs for any images on the domains it is provided.
Signed URLs
To produce a signed URL, you must enable secure URLs on your source and then provide your signature key to the URL builder.
Srcset Generation
The imgix-csharp library allows for generation of custom srcset
attributes, which can be invoked through BuildSrcSet()
. By default, the srcset
generated will allow for responsive size switching by building a list of image-width mappings.
Will produce the following attribute value, which can then be served to the client:
Fixed-Width Images
In cases where enough information is provided about an image's dimensions, BuildSrcSet()
will instead build a srcset
that will allow for an image to be served at different resolutions. The parameters taken into consideration when determining if an image is fixed-width are w
(width) and h
(height).
By invoking BuildSrcSet()
with either a width or height provided, a different srcset
will be generated for a fixed-size image instead.
Will produce the following attribute value:
For more information to better understand srcset
, we highly recommend Eric Portis' "Srcset and sizes" article which goes into depth about the subject.
Variable Quality
This library will automatically append a variable q
parameter mapped to each dpr
parameter when generating a fixed-width image srcset. This technique is commonly used to compensate for the increased file size of high-DPR images.
Since high-DPR images are displayed at a higher pixel density on devices, image quality can be lowered to reduce overall file size without sacrificing perceived visual quality. For more information and examples of this technique in action, see this blog post.
This behavior will respect any overriding q
value passed in as a parameter. Additionally, it can be disabled altogether by passing disableVariableQuality = true
to BuildSrcSet
.
This behavior specifically occurs when a fixed-width image is rendered, for example:
The above will generate a srcset with the following q
to dpr
query params
:
Fluid-Width Images
Custom Widths
In situations where specific widths are desired when generating srcset
pairs, a user can specify them by passing an array of positive integers as widths
:
Note: in situations where a srcset
is being rendered as a fixed image, any custom widths
passed in will be ignored.
Additionally, if both widths
and a width tol
erance are passed to the BuildSrcSet
method, the custom widths list will take precedence.
Width Ranges
In certain circumstances, you may want to limit the minimum or maximum value of the non-fixed (fluid-width) srcset
generated by the BuildSrcSet
method. To do this, you can specify the widths at which a srcset should begin
and end
:
Formatted version of the above srcset attribute:
Width Tolerance
The srcset
width tol
erance dictates the maximum tol
erated difference between an image's downloaded size and its rendered size.
For example, setting this value to 0.1 means that an image will not render more than 10% larger or smaller than its native size. In practice, the image URLs generated for a width-based srcset attribute will grow by twice this rate.
A lower tolerance means images will render closer to their native size (thereby increasing perceived image quality), but a large srcset list will be generated and consequently users may experience lower rates of cache-hit for pre-rendered images on your site.
By default, srcset width tol
erance is set to 0.08 (8 percent), which we consider to be the ideal rate for maximizing cache hits without sacrificing visual quality. Users can specify their own width tolerance by providing a positive scalar value as width tol
erance:
In this case, the width tol
erance is set to 20 percent, which will be reflected in the difference between subsequent widths in a srcset pair:
What is the ixlib
param on every request?
For security and diagnostic purposes, we sign all requests with the language and version of library used to generate the URL.
This can be disabled by passing false
for the includeLibraryParam
option to new UrlBuilder
:
Code of Conduct
Users contributing to or participating in the development of this project are subject to the terms of imgix's Code of Conduct.
More Core Libraries
- imgix-gobuildA Go client library for generating image URLs with imgixGo 12 a year ago
- imgix-javabuildA Java client library for generating URLs with imgixJava 19 a year ago
- imgix-phpbuildA PHP client library for generating URLs with imgixPHP 111 a year ago
- imgix-pythonbuildA Python client library for generating URLs with imgixPython 36 a year ago
- imgix-rbbuildA Ruby gem for generating image URLs with imgixRuby 76 a year ago
- imgix-swiftbuildA Swift client library for generating URLs with imgixSwift 25 9 months ago
- @imgix/js-corebuildA JavaScript client library for generating image URLs with imgixJavaScript 120 8 days ago