To begin creating imgix URLs programmatically, import the imgix library and create a URL builder. The URL builder can be reused to create URLs for any images on the domains it is provided.
For HTTPS support, specify the HTTPS flag like so:
To produce a signed URL, you must enable secure URLs on your source and then provide your signature key to the URL builder.
The imgix-python package allows for generation of custom srcset attributes, which can be invoked through
create_srcset(). 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:
In cases where enough information is provided about an image\'s dimensions,
create_srcset() 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
ar. By invoking
create_srcset() with either a width or the height and aspect ratio (along with
fit=crop, typically) 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.
Usage with UTF-8
For usage with non-ASCII characters, please be sure to that your project's source files specify UTF-8 encoding:
If you don\'t add this encoding, and you have an image with name for example \'tiburón.jpeg\', you will get the following error trying to run your script:
Run the following to execute the project's tests and code linter:
More Core Libraries
- imgix-csharpbuildA C# client library for generating image URLs with imgixC# 12 2 months ago
- imgix-elixirbuildAn Elixir client library for generating image URLs with imgixElixir 29 a month ago
- imgix-gobuildA Go client library for generating image URLs with imgixGo 2 2 months ago
- imgix-javabuildA Java client library for generating URLs with imgixJava 13 3 months ago
- imgix-phpbuildA PHP client library for generating URLs with imgixPHP 90 2 months ago
- imgix-rbbuildA Ruby gem for generating image URLs with imgixRuby 63 2 months ago
- imgix-swiftbuildA Swift client library for generating URLs with imgixSwift 19 14 days ago