<< More Tutorials
How to make an image responsive in Python 2 using rethumb?
The following code prints HTML with responsive images support. It's ready to use and defines three levels of resolution: 400px, 800px and original image.
Adapt and start using the following code in Python 2 (we use Picturefill as polyfill):
image_url = "http://images.rethumb.com/image_coimbra_999x999.jpg";
small_width = 400; # Image width for small resolutions (less than 400px).
large_width = 800; # Image width for medium resolutions (less than 800px).
image_width = 999; # Image original width (used for resolutions larger than 800px).
print("""
<script src="https://cdnjs.cloudflare.com/ajax/libs/picturefill/2.3.1/picturefill.min.js"></script>
<img src="http://api.rethumb.com/v1/width/{small_width}/{image_url}"
srcset="http://api.rethumb.com/v1/width/{small_width}/{image_url} {small_width}w,
http://api.rethumb.com/v1/width/{large_width}/{image_url} {large_width}w,
{image_url} {image_width}w"
sizes="100vw" />
""".format(image_url = image_url, small_width = small_width, large_width = large_width, image_width = image_width))
Start using this example now
Use the following commands to get started:
$ git clone https://github.com/rethumb/rethumb-python2-examples.git
$ cd rethumb-python2-examples
$ python responsive-images.js
More examples using Python 2
How to use rethumb in Python 2?
How to resize an image by width in Python 2 using rethumb?
How to resize an image by height in Python 2 using rethumb?
How to resize an image by width and height in Python 2 using rethumb?
How to create a square thumbnail from an image in Python 2 using rethumb?
How to read Exif data in json format from an image in Python 2 using rethumb?
How to make an image responsive in Python 2 using rethumb?
How to read GPS coordinates from an image in Python 2 using rethumb?
How to convert an image to JPG, GIF, PNG, TIF or WebP in Python 2 using rethumb?
How to resize an image to cover any dimensions in Python 2 using rethumb?