{ "info": { "author": "Jake Scaltreto", "author_email": "jscaltreto@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Utilities" ], "description": "# Django Simplethumb - Resize an image on the fly\n\n[![Build Status](https://api.travis-ci.org/jscaltreto/django-simplethumb.png)](http://travis-ci.org/jscaltreto/django-simplethumb)\n\nOriginally forked from django-imagefit (https://github.com/vinyll/django-imagefit)\n\nThis is an almost complete reworking of django-imagefit and it is not cross-compatable.\n\nThis implements a new template tag, `simplethumb`, which accepts two parameters:\n\n* Image file - a string representing a static file, or an ImageFieldFile instance (represeting\nan ImageField object).\n* Spec - the specification for what conversions to run on the image.\n\nThe tag returns the URL to the generated thumbnail.\n\nLike imagefit, the modified image isn't generated until it is requested by the browser. This\nis accomplished by encoding the spec into the generated file name. Once requested, the encoded\nspec is read in, then the original image is read off disk, processed, and the thumbnail\nreturned. The option (enabled by default) cache mechanism ensures that repeated requests\nfor the same image won't be reprocessed repeatedly.\n\nTheoretically, a ne'er-do-well attacker could spam your server with requests for images of\nvarying sizes at significant CPU cost. To address this, some rudimentary security is included:\nthe spec includes a check-byte, and is obfuscated by XORing an HMAC of the original image file\nname and its modification time (for cache busting). If the checksum fails, a 404 is returned.\n\nUsing the cache has the benefit that once a thumbnail becomes unreferenced\nit will eventually expire.\n\nI've only tested this in python 2.7, but I tried to make it python 3.x compatable\nas much as possible, someone can report back and/or PR.\n\n\n#### Benefits\n\n* Base image remains untouched on the server, and no new files are generated (except\nin the cache).\n* For static images, it uses django's staticfiles finder to locate the image on disk.\n* Define preset specs in your settings.py and reference them by name in your templates.\n* No database requirements, new or modified models, etc.\n* perfect match with mediaqueries to adapt on mobile, tablets and\nmulti-size screens.\n* better quality than html/css resizing and no large file download, great for\nlower bandwidth.\n\n\n\n#### Quick tour\n\nExample 1: render _/static/myimage.png_ image at a maximum size of 200 x 150 px:\n\n```html\n{% simplethumb \"myimage.png\" \"200x150\" %}\n```\n\nExample 2: render model's _news.image_ as a thumbnail (assuming _thumbnail_ is a defined preset):\n\n```html\n{% simplethumb \"news.image\" \"thumbnail\" %}\n```\n\nExample 3: render _/static/myimage.png_ image at a maximum cropped size of 150 x 150 px:\n\n```html\n{{ simplethumb \"myimage.png\" \"150x150,C\" }}\n```\n\nExample 3: render _/static/myimage.png_ with a maximum height of 150 px and convert to jpeg:\n\n```html\n{{ simplethumb \"myimage.png\" \"x150 jpg\" }}\n```\n\n#### What this is not\n\n* For creating specific model fields that resize image when model saves, see\n[django-imagekit](https://github.com/matthewwithanm/django-imagekit)\n* If you wish to avoid very large image on the server, consider resizing your original image\nbefore uploading it.\n\n\n## Installation\n\n#### Download\n\nVia pip ![latest version](https://img.shields.io/pypi/v/django-simplethumb.svg)\n\n```bash\npip install django-simplethumb\n```\n\nor the bleeding edge version\n\n```\npip install -e git+https://github.com/jscaltreto/django-simplethumb.git#egg=django-simplethumb\n```\n\n#### update INSTALLED_APPS\n\nIn _settings.py_, add _simplethumb_ in your INSTALLED_APPS\n\n```python\nINSTALLED_APPS = (\n\t\u2026,\n\t'simplethumb',\n)\n```\n\n#### urls.py\n\nSimplethumb is a resize service, therefore include its urls.\n\nPrefix it with whatever you want (here \"simplethumb\" for example):\n\n```python\nurlpatterns = urlpatterns('',\n \u2026\n url(r'^simplethumb/', include('simplethumb.urls')),\n)\n```\n\n## Configuration\n\n#### Presets\n\nPresets are configuration names that hold width and height (and maybe more later on).\nSimplethumb is already shipped with 3 presets : _thumbnail_ (80x80), _medium_ (320x240)\nand _original_ (no resizing).\n\nYou may override them or create new ones through settings.py\n\n\nCustom presets examples :\n\n```python\nSIMPLETHUMB_PRESETS = {\n 'thumbnail': '64x64,C',\n 'my_preset1': '300x200 jpeg',\n 'my_preset2': '100x',\n}\n```\n\n\n#### Cache\n\nBecause resizing an image on the fly is expensive, django cache is enabled\nby default.\n\nYou can customize the default cache preferences by overriding default values\ndescribed below via settings.py :\n\n```python\n# enable/disable server cache\nSIMPLETHUMB_CACHE_ENABLED = True\n# set the cache name specific to simplethumb with the cache dict\nSIMPLETHUMB_CACHE_BACKEND_NAME = 'simplethumb'\n# set the cache TTL (default is 30 days)\nSIMPLETHUMB_CACHE_TTL = 3600 * 24 * 30\n\nCACHES = {\n 'simplethumb': {\n 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',\n 'LOCATION': os.path.join(tempfile.gettempdir(), 'django_simplethumb')\n }\n }\n```\n\nNote that `CACHES` default values will be merge with yours from _settings.py_\n\n#### Expires Header\n\nSimplethumb comes with Expires header to tell the browser whether it should request the\nresource from the server or use the cached version.\nThis has two core benefits. The browser will be using the cached version of the resource\nin the second load and page load will be much faster. Also, it will require fewer requests to the server.\n\nAs a page score parameter, static resources used in a web page should be containing\nan Expires information for better performance.\n\nThe default value of the expires header is the same as the cache TTL (30 days).\nYou can override this value via settings.py as:\n\n```python\nSIMPLETHUMB_EXPIRE_HEADER = 3600 # for 1 hour\n```\n\n#### Other Configuration Options\n\n* `SIMPLETHUMB_DEFAULT_JPEG_QUALITY` - Default image quality to use when saving JPEG (default is 60)\n* `SIMPLETHUMB_DEFAULT_OPTIMIZE_PNG` - Whether to optimize PNG files (default False)\n* `SIMPLETHUMB_HMAC_KEY` - Key to use when generating the HMAC for encoding the spec. (Default is settings.SECRET_KEY)\n\n## Usage\nThe spec string used with the tag can contain the following tokens. While some tokens may be combined,\nsome will conflict and could produce unexpected results. Common sense is encouraged (i.e. don't try\nto convert an image to both JPEG and PNG at the same time).\n\n* Resize Image - 'WxH' - Proportionally scale an image to fit within a box _W_ wide and _H_ high. e.g. `300x400`\n* Fit to Width - 'Wx' - Proportionally scale an image to have width _W_. e.g. `300x`\n* Fit to Height - 'xH' - Proportionally scale an image to have height _H_. e.g. `x400`\n* Scale Image - 'P%' - Proportionally scale an image by _P_ percent. e.g. `50%`\n* Crop Image - 'WxH,C - Scale an image to *fill* a box _W_ wide and _H_ high, cropping off any excess. e.g. '100x100,C'\n* Convert image to JPEG - 'jpeg' - Convert an image to JPEG (optionally include a 'quality' setting between 1 and 100). e.g. 'jpeg80'\n* Convert image to PNG - 'png' - Convert an image to PNG (optionally include the letter _O_ to optimize). e.g. 'pngO'\n* Crop Image to Ratio - 'C_X_:_Y_' - Crops an image to the specified aspect ratio. This is performed before resizing. e.g. 'C16:9'\n\nIf you don't specify a format to convert to, the original image format will be used. Though it will be rerendered\nusing the default quality or optimization setting defined.\n\nWith the exception of 'Scale Image', none of the resize commands will _increase_ the size of an image. So if the\nimage is smaller than the specified bounds, the image will not be scaled. Also note that all crops are \"center cropped\"\n\nBecause the spec will ultimately be encoded in a small binary format for inclusion in the image url, there\nare some hard limits on the sizes which can be specified. Anything higher than these limits will be truncated:\n\n* Width and Height attributes are limited to 13 bits, meaning the maximum image size is 8191x8191px (about 67MP, pretty big).\n* The Percent scale attribute is limited to 10 bits, meaning an image can only be scaled up to 1023%.\n* Crop ratio is stored as a custom 16-bit unsigned floating point (5 bit exponent, 11 bit mantissa), so there are limits related to precission. It should be good enough for image cropping.\n\n## Troubleshooting\n\n\n### \"decoder jpeg not available\" on Mac OSX\n\n\nYou may have installed PIL through pip or easy_install that\ndoes not install libjpeg dependency.\n\nIf so :\n\n1. Uninstall pil via pip\n2. Install pip via homebrew: `brew install pil`\n3. Reinstall pil via pip: `pip install pil`\n\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/jscaltreto/django-simplethumb", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "django-simplethumb", "package_url": "https://pypi.org/project/django-simplethumb/", "platform": "", "project_url": "https://pypi.org/project/django-simplethumb/", "project_urls": { "Homepage": "http://github.com/jscaltreto/django-simplethumb" }, "release_url": "https://pypi.org/project/django-simplethumb/0.3.1/", "requires_dist": [ "django", "six", "django-appconf", "Pillow" ], "requires_python": "", "summary": "Django template tag to do some basic image processing, and cache the resulting image", "version": "0.3.1" }, "last_serial": 3735228, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "c5df7efcc5c876cca19e6994292d9b74", "sha256": "4f24fb511df97e54710a881adffdd7ded313b73a6fb9a206fdaa96759e25ba6d" }, "downloads": -1, "filename": "django-simplethumb-0.1.tar.gz", "has_sig": false, "md5_digest": "c5df7efcc5c876cca19e6994292d9b74", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10874, "upload_time": "2017-11-24T01:16:05", "url": "https://files.pythonhosted.org/packages/0b/d7/69fea6c2d2fd5fd60f394032348999a41bde47fc16da80568dc30ff55a0a/django-simplethumb-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "80197f7dd6c33a487f7fadeffce65642", "sha256": "bafb4b2be8ef6e375d68b2b30f1e12964689e7590b68044a10a2e7848d75d16f" }, "downloads": -1, "filename": "django-simplethumb-0.2.tar.gz", "has_sig": false, "md5_digest": "80197f7dd6c33a487f7fadeffce65642", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11907, "upload_time": "2017-12-26T21:10:39", "url": "https://files.pythonhosted.org/packages/60/88/1653fc48ded3c02de3b3bc98620b902a609c7fc993be3139927d913c0672/django-simplethumb-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "b2cd7dc5c1f712b9adb9b6160206058c", "sha256": "f6e144dbf90898581a992653c3f1e3c7e8b2b3caaec2c084b9e8b49734d0f079" }, "downloads": -1, "filename": "django-simplethumb-0.2.1.tar.gz", "has_sig": false, "md5_digest": "b2cd7dc5c1f712b9adb9b6160206058c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11909, "upload_time": "2017-12-26T21:32:37", "url": "https://files.pythonhosted.org/packages/f0/4b/91651f65aa5daa094b2c12d9fcee07a7cf742476aef846f4d7e72f96d087/django-simplethumb-0.2.1.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "fee621f25ec4aea3d28e7afc3e805b12", "sha256": "0ff126619dcd277c7990d045fd4e6a3c999c84a9e89aa75faffd526e83f17854" }, "downloads": -1, "filename": "django_simplethumb-0.3.0-py2-none-any.whl", "has_sig": false, "md5_digest": "fee621f25ec4aea3d28e7afc3e805b12", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 21899, "upload_time": "2018-03-31T14:39:49", "url": "https://files.pythonhosted.org/packages/59/af/2b1cd6b875d15bb893652904ccd2b6a3bcbcf36ac755ec935256384861c0/django_simplethumb-0.3.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "61f9edd8fc1706b65128c7c09be38455", "sha256": "c42e99cbb051e9fcdde1642da5ab750d8244afab849a9b6073cc0cce3b482978" }, "downloads": -1, "filename": "django_simplethumb-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "61f9edd8fc1706b65128c7c09be38455", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21898, "upload_time": "2018-03-31T14:40:24", "url": "https://files.pythonhosted.org/packages/5d/15/fca26f7be1d0dfb3cb449c87958fce76426c7c7f022330ca6710668701fd/django_simplethumb-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3567c96626d492c73adb7699e6a16775", "sha256": "0775fd75b2c313a22eeceacf0273f6fb4073b28f2d08e7d3607aade5c177d4de" }, "downloads": -1, "filename": "django-simplethumb-0.3.0.tar.gz", "has_sig": false, "md5_digest": "3567c96626d492c73adb7699e6a16775", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18510, "upload_time": "2018-03-31T14:39:50", "url": "https://files.pythonhosted.org/packages/6c/17/dfb51e45d3d833340b66fd0662524a137a9e5b2de877aadcd614aaabcea6/django-simplethumb-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "01389b2ec40015c389fee8c47038a452", "sha256": "90fb9b2a6340d1c06ea10a847a889c2530b7e5ea4ff0ad0a014cc0084007b171" }, "downloads": -1, "filename": "django_simplethumb-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "01389b2ec40015c389fee8c47038a452", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17199, "upload_time": "2018-04-04T20:26:13", "url": "https://files.pythonhosted.org/packages/d3/15/46b4f1b4b52e93738246a59bc17bb69bef23a528bbdee868d4b3dcd8900d/django_simplethumb-0.3.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "63273810b88a24528bdfd7983918d8a5", "sha256": "2e57f0ec13c8a70c8eea5540f5db9b9e22e6354b65bf3713374e1c860f551299" }, "downloads": -1, "filename": "django-simplethumb-0.3.1.tar.gz", "has_sig": false, "md5_digest": "63273810b88a24528bdfd7983918d8a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18510, "upload_time": "2018-04-04T20:26:14", "url": "https://files.pythonhosted.org/packages/20/d2/dec4f14c92e2233cf79394af1232d1bdb5a555d5016aa04ad0d27e2a8772/django-simplethumb-0.3.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "01389b2ec40015c389fee8c47038a452", "sha256": "90fb9b2a6340d1c06ea10a847a889c2530b7e5ea4ff0ad0a014cc0084007b171" }, "downloads": -1, "filename": "django_simplethumb-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "01389b2ec40015c389fee8c47038a452", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17199, "upload_time": "2018-04-04T20:26:13", "url": "https://files.pythonhosted.org/packages/d3/15/46b4f1b4b52e93738246a59bc17bb69bef23a528bbdee868d4b3dcd8900d/django_simplethumb-0.3.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "63273810b88a24528bdfd7983918d8a5", "sha256": "2e57f0ec13c8a70c8eea5540f5db9b9e22e6354b65bf3713374e1c860f551299" }, "downloads": -1, "filename": "django-simplethumb-0.3.1.tar.gz", "has_sig": false, "md5_digest": "63273810b88a24528bdfd7983918d8a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18510, "upload_time": "2018-04-04T20:26:14", "url": "https://files.pythonhosted.org/packages/20/d2/dec4f14c92e2233cf79394af1232d1bdb5a555d5016aa04ad0d27e2a8772/django-simplethumb-0.3.1.tar.gz" } ] }