Skip to main content

Image transforming WSGI middleware

Project description

This package provides a WSGI middleware component which automatically scales images according to the width and height property in the <img> tag.

To configure the middleware, pass in a string for secret; this may be any string internal to the system.

You can also set filter to select the scaling filter. The available filters are nearest, bilinear, bicubic and antialias. The default is antialias.

If you want to change the compression level for JPEG images, then you can set the quality option to a value between 1 (worst) and 95 (best). The default is 80.

By default all image URLs are rewritten. With limit_to_application_url you can limit the rewriting to relative URLs and absolute URLs below the application URL.

If you want to use namespaces for tags in your content, then you need to specify try_xhtml which uses an XML parser for the content and preserves namespaces. This is useful if you use esi:include for example. Your content needs to be well formed for this to work, that includes a proper doctype etc.

Usage

The middleware operates in two phases, on HTML documents and images respectively.

When processing HTML documents, it looks for image tags in the document soup:

<img src="some_image.png" width="640" height="480" />

In the case it finds such an image element, it rewrites the URL to include scaling information which the middleware will read when the image is served through it.

The image will be proportionally scaled, so it fits into the given size. If you only set one of width or height, then the image will only be limited to that, but still proportionally scaled.

This effectively means that application developers needn’t worry about image scaling; simply put the desired size in the HTML document.

Note that this middleware is protected from DoS attacks (which is important for any middleware that does significant processing) by signing all URLs with an SHA digest signature.

Credits

Changelog

0.7 (released 2009-03-18)

  • Don’t use python 2.6 syntax. [seletz]

  • Handle empty content bodies, which can occure for redirects. [fschulze]

  • Added support for xhtml, which allows the inclusion of namespace tags. [fschulze]

  • Added option to limit the url rewriting to urls below the application url. [fschulze]

  • Added scaling filter support. [fschulze]

  • Support image tags with only one of the width or height attributes set. [fschulze]

  • Fix UnboundLocalError for respones with untransformed image. [fschulze]

  • Fix importing of PIL. The old way assumed the broken egg installation. [fschulze]

  • Made tests run. [fschulze]

0.6 (released 2008-10-11)

  • Require to pass in a secret parameter to configure middleware security. [malthe]

0.5 (released 2008-10-11)

  • Rewritten URLs are now signed by the middleware to ensure that bitblt requests are only crafted by the middleware. This is required to shield against DoS attacks. [malthe]

0.4 (released 2008-10-11)

  • Fixed path handling. [malthe]

  • Added HTML document processing which scans document for image tags and rewrite image src attribute to include “bitblt” traversing directive. This makes it work as an actual middleware, since the application semantics are then unchanged. [malthe]

  • No longer accept query parameters, but instead require traversing directive “/bitblt-<width>x<height>”. [malthe]

  • Removed functionality to MIME-type convert. [malthe]

0.3 (released 2008-10-10)

  • Made logic robust to unexpected parameters. [malthe]

  • Fixed bug where parameters would be drawn from the WSGI environment. [malthe]

  • Added mimetype conversion. [malthe]

0.2 (released 2008-10-08)

  • Fixed entry point name.

0.1 (released 2008-10-03)

  • Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repoze.bitblt-0.7.tar.gz (16.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page