{ "info": { "author": "Ingeniweb", "author_email": "support@ingeniweb.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": ".. contents::\n\nDescription\n-----------\n\n\u00ecw.thumbs` is used to serve image thumbnail. The thumbnail is cached in a\ndirectory and served with `paste.fileapp` so correct headers (ETag,\nIf-Modified, etc.) are returned.\n\n`iw.thumbs` is highly configurable but if you use `Paste` to serve your\napplication you probably only need to read the last part of this documentation.\n\nUsage\n-----\n\nThe `Thumb` middleware take four arguments:\n\n- application: the wsgi application to wrap.\n\n- url_parser: a callable to retrieve the size of the thumbnail and the\n attending size as a tuple (width, height)\n Default: `iw.thumbs.url.url_parser`\n The default value match urls like `/thumbs/100x100/path/to/image.png` and\n return ('/path/to/image.png', (100, 100))\n\n- url_regexp: a regexp passed as argument to the default url_parser. The regexp\n must have groups named path, width and height.\n Default: '^/+thumbs/+(?P[0-9]{2,3})x(?P[0-9]{2,3})/{0,1}(?P/.+)'\n\n- image_fetcher: a callable to retrieve the real image path\n Default: `iw.thumbs.image_fetcher`\n The default value return the `PATH_INFO` so you may override it. This callable\n is used to retrieve image from file system but you can also use it to retrieve\n image from other location like proxy, ftp, etc.\n\n- image_dir: a directory where images are stored. Used by `image_fetcher` if\n the default one is used.\n\n- cache_dir: a path to the directory used to cache thumbnails (required)\n\n- debug: debug mode. Default: False \n\nExample\n-------\n\nWrite a method to retrieve your image path from the `PATH_INFO`::\n\n >>> def image_fetcher(path_info):\n ... return os.path.join(package_dir, *path_info.split('/')[1:])\n\nWrap your application with the middleware::\n\n >>> from iw.thumbs.middleware import Thumbs\n >>> app = Thumbs(test_app, image_fetcher=image_fetcher, cache_dir=cache_dir)\n\nThen ask for an image::\n\n >>> environ = {'REQUEST_METHOD':'GET',\n ... 'PATH_INFO':'/thumbs/50x50/tests/logo.png'}\n >>> print app.get_app(environ)\n \n\nOverride the default url regexp::\n\n >>> regexp = '^/my_thumbs/(?P[0-9]+)x(?P[0-9]+)(?P/.+)'\n >>> app = Thumbs(test_app, image_fetcher=image_fetcher, cache_dir=cache_dir,\n ... url_regexp=regexp)\n\n >>> environ = {'REQUEST_METHOD':'GET', 'PATH_INFO':'/my_thumbs/50x50/tests/logo.png'}\n >>> print app.get_app(environ)\n \n\nIf the path does not match an image, the `test_app` is served:: \n\n >>> environ = {'REQUEST_METHOD':'GET', 'PATH_INFO':'/index.html'}\n >>> print app.get_app(environ)\n \n\nUsing sizes names\n-----------------\n\nYou can use size names::\n\n >>> app = Thumbs(test_app, image_fetcher=image_fetcher, cache_dir=cache_dir,\n ... url_regexp='/thumbs/(?P%s)(?P/.*)',\n ... url_parser='iw.thumbs.url:size_parser',\n ... sizes={'thumb': (100,100), 'large': (600,600)})\n\n >>> environ = {'REQUEST_METHOD':'GET', 'PATH_INFO':'/thumbs/large/tests/logo.png'}\n >>> print app.get_app(environ)\n \n\nImplementing your own parser\n----------------------------\n\nYou need a callable who return a callable and the compiled regexp.\n\nLet's define our strategy with a regexp::\n\n >>> re_thumb = '^/thumbs(?P/.*)'\n\nThen implement it with a parser::\n\n >>> import re\n >>> def custom_parser(regexp, **kwargs):\n ... regexp = re.compile(regexp)\n ... def parser(url):\n ... m = regexp.match(url)\n ... if m:\n ... path = m.group('path')\n ... return path, (100, 100)\n ... return parser, regexp\n\nCheck this work::\n\n >>> app = Thumbs(test_app, image_fetcher=image_fetcher, cache_dir=cache_dir,\n ... url_regexp=re_thumb, url_parser=custom_parser)\n\n >>> environ = {'REQUEST_METHOD':'GET', 'PATH_INFO':'/thumbs/tests/logo.png'}\n >>> print app.get_app(environ)\n \n\nUtils\n-----\n\nResize an image file to the specified destination at `size`::\n\n >>> from iw.thumbs.image import resize\n >>> thumbnail = os.path.join(cache_dir, 'thumb.png')\n >>> print resize(image_path, thumbnail, size=(50, 50))\n /..._cache/thumb.png\n >>> os.path.isfile(thumbnail)\n True\n\n\n\nPaste factory\n-------------\n\nThe package provide a `Paste` factory.\n\nHere is a sample configuration::\n\n [app:main]\n use = egg:Paste#urlmap\n /images = thumbs_app\n / = middlewares\n \n # a standalone application to serve files in image_dir. The application is a\n # static application wrapped with the iw.thumbs middleware\n [app:thumbs_app]\n use = egg:iw.thumbs\n url_regexp = ^/+(?P[0-9]+)x(?P[0-9]+)/{0,1}(?P/.+)\n image_dir = %(here)s/images\n cache_dir = %(here)s/images_cache\n \n [pipeline:middlewares]\n pipeline = thumbs named_thumbs test_app\n \n # an example tho override the default regexp\n [filter:thumbs]\n use = egg:iw.thumbs\n url_regexp = ^/+(?P[0-9]+)x(?P[0-9]+)/{0,1}(?P/.+)\n image_dir = %(here)s/images\n cache_dir = %(here)s/images_cache\n \n # another example using sizes names\n [filter:named_thumbs]\n use = egg:iw.thumbs\n url_regexp = ^/(?P%s)(?P/.+)\n url_parser = iw.thumbs.url:size_parser\n image_dir = %(here)s/images\n cache_dir = %(here)s/images_cache\n sizes = \n thumb = 200x200\n large = 600x600\n \n [app:test_app]\n use = egg:Paste#static\n document_root = %(here)s/\n \n [server:main]\n use = egg:Paste#http\n host = 0.0.0.0", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "wsgi imaging", "license": "GPL", "maintainer": null, "maintainer_email": null, "name": "iw.thumbs", "package_url": "https://pypi.org/project/iw.thumbs/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/iw.thumbs/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/iw.thumbs/1.2/", "requires_dist": null, "requires_python": null, "summary": "A wsgi middleware to generate and serve image thumbnails.", "version": "1.2" }, "last_serial": 754510, "releases": { "0.5": [ { "comment_text": "", "digests": { "md5": "0dccb54114e36ca54ded8c1e7a9d21f4", "sha256": "ebc3ddfec4274431a3918a529873917168ab6a9501c8266f539a0c873efe62f2" }, "downloads": -1, "filename": "iw.thumbs-0.5-py2.4.egg", "has_sig": false, "md5_digest": "0dccb54114e36ca54ded8c1e7a9d21f4", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 15358, "upload_time": "2008-10-23T15:22:12", "url": "https://files.pythonhosted.org/packages/f4/15/71095b47a04b52d979a255418c71f2362b6204836455b2a7b4c3eb3ab990/iw.thumbs-0.5-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "3bff5c3ac2bfac44ded4068efb04f0fb", "sha256": "cf0468fbb60d6dec15f15529959f093b84eed596c1420f3cbd6e3025362aefeb" }, "downloads": -1, "filename": "iw.thumbs-0.5.tar.gz", "has_sig": false, "md5_digest": "3bff5c3ac2bfac44ded4068efb04f0fb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10193, "upload_time": "2008-10-23T15:22:11", "url": "https://files.pythonhosted.org/packages/89/34/c08fbb945eeb1081b70b2bf5ac318b58700b9ccee37d55423fc74bb93fd8/iw.thumbs-0.5.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "22eb81cdbb5419178a767474e5ff26da", "sha256": "548b7f5d8b4a0bad649069771fcc856fc8594f79dfddb3d066002431d61ab849" }, "downloads": -1, "filename": "iw.thumbs-1.0-py2.4.egg", "has_sig": false, "md5_digest": "22eb81cdbb5419178a767474e5ff26da", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 16341, "upload_time": "2008-10-29T16:25:27", "url": "https://files.pythonhosted.org/packages/1d/5a/f018a28d7bf5c5d89dbc058ae3523afd42a528322cd18a5c5ca2d2084332/iw.thumbs-1.0-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "66075fde9090efee1309be3efcf8056f", "sha256": "643ec70d890b486ea5d868addb6caee94fa83bf88247271d714c38a451c616a6" }, "downloads": -1, "filename": "iw.thumbs-1.0.tar.gz", "has_sig": false, "md5_digest": "66075fde9090efee1309be3efcf8056f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 81253, "upload_time": "2008-10-29T16:25:27", "url": "https://files.pythonhosted.org/packages/31/b4/572ae502c6ae9516726995c9699e618181cff259f85c15b964d7a31c4f18/iw.thumbs-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "198d9422d93d5188debe266a25169a01", "sha256": "49b4788c01f7818446e874700b6dcb44b8cf04b80176fec0329131257ba414bf" }, "downloads": -1, "filename": "iw.thumbs-1.1-py2.4.egg", "has_sig": false, "md5_digest": "198d9422d93d5188debe266a25169a01", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 18979, "upload_time": "2008-11-04T22:46:46", "url": "https://files.pythonhosted.org/packages/82/8e/5caeb3605bebd1e023e559110e543b05638561423263038df58307a79e3e/iw.thumbs-1.1-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "1b7f8d769533b6d1303922b1f8e85c26", "sha256": "dcc6d682c9ad4e4c83aa7e74863736298f4ac654d2a32fb86c938a8295b7fdbd" }, "downloads": -1, "filename": "iw.thumbs-1.1.tar.gz", "has_sig": false, "md5_digest": "1b7f8d769533b6d1303922b1f8e85c26", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 82584, "upload_time": "2008-11-04T22:46:46", "url": "https://files.pythonhosted.org/packages/51/f5/0d9353fab4af13dea12fad7e8859877ef89f5bcea8de5a70da008c852c50/iw.thumbs-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "aa672d01a976f1f05d99c30c9e96ebde", "sha256": "2c0322b01759904acf714c561f54ccf4008d9ac555dd2b26465b6e9b01ad72e1" }, "downloads": -1, "filename": "iw.thumbs-1.2.tar.gz", "has_sig": false, "md5_digest": "aa672d01a976f1f05d99c30c9e96ebde", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 83043, "upload_time": "2008-11-22T14:35:04", "url": "https://files.pythonhosted.org/packages/99/4b/1b37076432ddf40afae7b48788705fe1c132628cd0ddece0743342ce7d32/iw.thumbs-1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "aa672d01a976f1f05d99c30c9e96ebde", "sha256": "2c0322b01759904acf714c561f54ccf4008d9ac555dd2b26465b6e9b01ad72e1" }, "downloads": -1, "filename": "iw.thumbs-1.2.tar.gz", "has_sig": false, "md5_digest": "aa672d01a976f1f05d99c30c9e96ebde", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 83043, "upload_time": "2008-11-22T14:35:04", "url": "https://files.pythonhosted.org/packages/99/4b/1b37076432ddf40afae7b48788705fe1c132628cd0ddece0743342ce7d32/iw.thumbs-1.2.tar.gz" } ] }