{"id":13415978,"url":"https://github.com/SmileyChris/easy-thumbnails","last_synced_at":"2025-03-14T23:31:12.043Z","repository":{"id":686554,"uuid":"330557","full_name":"SmileyChris/easy-thumbnails","owner":"SmileyChris","description":"Easy thumbnails for Django","archived":false,"fork":false,"pushed_at":"2024-09-12T12:40:26.000Z","size":936,"stargazers_count":1385,"open_issues_count":93,"forks_count":318,"subscribers_count":32,"default_branch":"master","last_synced_at":"2024-10-29T15:03:18.050Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://easy-thumbnails.readthedocs.org/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SmileyChris.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2009-10-08T03:44:26.000Z","updated_at":"2024-10-24T18:44:25.000Z","dependencies_parsed_at":"2024-01-11T19:17:17.641Z","dependency_job_id":"6de3e65e-87b6-4e97-9c25-ea831c5a86ee","html_url":"https://github.com/SmileyChris/easy-thumbnails","commit_stats":{"total_commits":676,"total_committers":102,"mean_commits":6.627450980392157,"dds":0.5044378698224852,"last_synced_commit":"d4e8d0cb72c712f0e2310ac05ee5b520c304d684"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmileyChris%2Feasy-thumbnails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmileyChris%2Feasy-thumbnails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmileyChris%2Feasy-thumbnails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmileyChris%2Feasy-thumbnails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SmileyChris","download_url":"https://codeload.github.com/SmileyChris/easy-thumbnails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243663461,"owners_count":20327299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T21:00:53.412Z","updated_at":"2025-03-14T23:31:12.027Z","avatar_url":"https://github.com/SmileyChris.png","language":"Python","readme":"===============\r\nEasy Thumbnails\r\n===============\r\n\r\n.. image:: https://img.shields.io/pypi/v/easy-thumbnails.svg\r\n    :target: https://pypi.python.org/pypi/easy-thumbnails/\r\n\r\n.. image:: https://github.com/SmileyChris/easy-thumbnails/actions/workflows/python.yml/badge.svg\r\n    :alt: Build Status\r\n    :target: https://github.com/SmileyChris/easy-thumbnails/actions/workflows/python.yml\r\n\r\n\r\nA powerful, yet easy to implement thumbnailing application for Django 4.2+\r\n\r\nBelow is a quick summary of usage. For more comprehensive information, view the\r\n`full documentation`__ online or the peruse the project's ``docs`` directory.\r\n\r\n__ http://easy-thumbnails.readthedocs.org/en/latest/index.html\r\n\r\n\r\nBreaking News\r\n=============\r\n\r\nVersion 2.8.0 adds support for thumbnailing SVG images when installed with the ``[svg]`` extra.\r\n\r\nOf course it doesn't make sense to thumbnail SVG images, because being in vector format they can\r\nscale to any size without quality of loss. However, users of easy-thumbnails may want to upload and\r\nuse SVG images just as if they would be PNG, GIF or JPEG. They don't necessarily care about the\r\nformat and definitely don't want to convert them to a pixel based format. What they want is to reuse\r\ntheir templates with the templatetag thumbnail and scale and crop the images to whatever their\r\n`\u003cimg src=\"...\" width=\"...\" height=\"...\"\u003e` has been prepared for.\r\n\r\nThis is done by adding an emulation layer named VIL, which aims to be compatible with the\r\n`PIL \u003chttps://python-pillow.org/\u003e`_ library. All thumbnailing operations, such as scaling and\r\ncropping behave like pixel based images. The final filesize of such thumbnailed SVG images doesn't\r\nof course change, but their width/height and bounding box may be adjusted to reflect the desired\r\nsize of the thumbnailed image.\r\n\r\n.. note:: This feature is new and experimental, hence feedback about its proper functioning in\r\n          third parts applications is highly appreciated.\r\n\r\n\r\nInstallation\r\n============\r\n\r\nRun ``pip install easy-thumbnails``.\r\n\r\nAdd ``easy_thumbnails`` to your ``INSTALLED_APPS`` setting:\r\n\r\n.. code-block:: python\r\n\r\n    INSTALLED_APPS = (\r\n        ...\r\n        'easy_thumbnails',\r\n    )\r\n\r\nRun ``manage.py migrate easy_thumbnails``.\r\n\r\n\r\nExample usage\r\n=============\r\n\r\nThumbnail options can be predefined in ``settings.THUMBNAIL_ALIASES`` or just\r\nspecified in the template or Python code when run.\r\n\r\nUsing a predefined alias\r\n------------------------\r\n\r\nGiven the following setting:\r\n\r\n.. code-block:: python\r\n\r\n    THUMBNAIL_ALIASES = {\r\n        '': {\r\n            'avatar': {'size': (50, 50), 'crop': True},\r\n        },\r\n    }\r\n\r\nTemplate:\r\n\r\n.. code-block:: html+django\r\n\r\n    {% load thumbnail %}\r\n    \u003cimg src=\"{{ profile.photo|thumbnail_url:'avatar' }}\" alt=\"\" /\u003e\r\n\r\nPython:\r\n\r\n.. code-block:: python\r\n\r\n    from easy_thumbnails.files import get_thumbnailer\r\n    thumb_url = get_thumbnailer(profile.photo)['avatar'].url\r\n\r\nManually specifying size / options\r\n----------------------------------\r\n\r\nTemplate:\r\n\r\n.. code-block:: html+django\r\n\r\n    {% load thumbnail %}\r\n    \u003cimg src=\"{% thumbnail profile.photo 50x50 crop %}\" alt=\"\" /\u003e\r\n\r\nPython:\r\n\r\n.. code-block:: python\r\n\r\n    from easy_thumbnails.files import get_thumbnailer\r\n    options = {'size': (100, 100), 'crop': True}\r\n    thumb_url = get_thumbnailer(profile.photo).get_thumbnail(options).url\r\n\r\nUsing in combination with other thumbnailers\r\n--------------------------------------------\r\n\r\nAlternatively, you load the templatetags by {% load easy_thumbnails_tags %} \r\ninstead of traditional {% load thumbnail %}. It's especially useful in \r\nprojects that do make use of multiple thumbnailer libraries that use the \r\nsame name (`thumbnail`) for the templatetag module:\r\n\r\n.. code-block:: html+django\r\n\r\n    {% load easy_thumbnails_tags %}\r\n    \u003cimg src=\"{% thumbnail profile.photo 50x50 crop %}\" alt=\"\" /\u003e\r\n\r\nFields\r\n======\r\n\r\nYou can use ``ThumbnailerImageField`` (or ``ThumbnailerField``) for easier\r\naccess to retrieve or generate thumbnail images.\r\n\r\nFor example:\r\n\r\n.. code-block:: python\r\n\r\n    from easy_thumbnails.fields import ThumbnailerImageField\r\n\r\n    class Profile(models.Model):\r\n        user = models.OneToOneField('auth.User')\r\n        photo = ThumbnailerImageField(upload_to='photos', blank=True)\r\n\r\nAccessing the field's predefined alias in a template:\r\n\r\n.. code-block:: html+django\r\n\r\n    {% load thumbnail %}\r\n    \u003cimg src=\"{{ profile.photo.avatar.url }}\" alt=\"\" /\u003e\r\n\r\nAccessing the field's predefined alias in Python code:\r\n\r\n.. code-block:: python\r\n\r\n    thumb_url = profile.photo['avatar'].url\r\n\r\n\r\nThumbnail options\r\n=================\r\n\r\n``crop``\r\n--------\r\n\r\nBefore scaling the image down to fit within the ``size`` bounds, it first cuts\r\nthe edges of the image to match the requested aspect ratio.\r\n\r\nUse ``crop=\"smart\"`` to try to keep the most interesting part of the image,\r\n\r\nUse ``crop=\"0,10\"`` to crop from the left edge and a 10% offset from the\r\ntop edge. Crop from a single edge by leaving dimension empty (e.g.\r\n``crop=\",0\"``). Offset from the right / bottom by using negative numbers\r\n(e.g., crop=\"-0,-10\").\r\n\r\nOften used with the ``upscale`` option, which will allow enlarging of the image\r\nduring scaling.\r\n\r\n``quality=XX``\r\n--------------\r\n\r\nChanges the quality of the output JPEG thumbnail. Defaults to ``85``.\r\n\r\nIn Python code, this is given as a separate option to the ``get_thumbnail``\r\nmethod rather than just alter the other.\r\n\r\n``keep_icc_profile``\r\n--------------------\r\n\r\nIf `True`, when saving a thumbnail with the alias that defines this option, the\r\nICC profile of the image will be preserved in the thumbnail, if present in the first place.\r\n\r\n\r\nOther options\r\n-------------\r\n\r\nValid thumbnail options are determined by the \"thumbnail processors\" installed.\r\n\r\nSee the `reference documentation`__ for a complete list of options provided by\r\nthe default thumbnail processors.\r\n\r\n__ http://easy-thumbnails.readthedocs.org/en/latest/ref/processors/\r\n","funding_links":[],"categories":["Third-Party Packages","Thumbnail","Python","Django Utilities","缩略图"],"sub_categories":["Static Assets","Podcasts"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSmileyChris%2Feasy-thumbnails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSmileyChris%2Feasy-thumbnails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSmileyChris%2Feasy-thumbnails/lists"}