Skip to content

Commit 0a6f4e0

Browse files
committed
point documentation of this package to Plone docs
1 parent 41be735 commit 0a6f4e0

File tree

2 files changed

+3
-99
lines changed

2 files changed

+3
-99
lines changed

README.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ and BLOBs to be configured in zope.conf.
1212

1313
plone.supermodel handlers are registered.
1414

15-
See the ``usage.rst`` doctest for more details.
15+
See the `image handling section of Plone documentation <https://6.docs.plone.org/classic-ui/images.html#all-image-scales-in-the-srcset>`_ to learn how to
16+
use the features provided by this package.
1617

1718

1819
Source Code
1920
===========
2021

21-
Note: This packages is licensed under a *BSD license*.
22+
Note: This packages is licensed under a *BSD license*.
2223
Please do not add dependencies on GPL code!
2324

2425
Contributors please read the document `Process for Plone core's development <https://docs.plone.org/develop/coredev/docs/index.html>`_

plone/namedfile/usage.rst

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -403,100 +403,3 @@ We will test this with a dummy request, faking traversal::
403403
'text/plain'
404404
>>> request.response.getHeader('Content-Disposition')
405405
"attachment; filename*=UTF-8''test.txt"
406-
407-
408-
Image scales
409-
------------
410-
411-
This package can handle the creation, storage, and retrieval of arbitrarily
412-
sized scaled versions of images stored in NamedImage or NamedBlobImage fields.
413-
414-
Image scales are accessed via an @@images view that is available for any item
415-
providing ``plone.namedfile.interfaces.IImageScaleTraversable``. There are
416-
several ways that you may reference scales from page templates.
417-
418-
1. for full control you may do the tag generation explicitly::
419-
420-
<img tal:define="images context/@@images;
421-
thumbnail python: images.scale('image', width=64, height=64);"
422-
tal:condition="thumbnail"
423-
tal:attributes="src thumbnail/url;
424-
width thumbnail/width;
425-
height thumbnail/height" />
426-
427-
This would create an up to 64 by 64 pixel scaled down version of the image
428-
stored in the "image" field. It also allows for passing in additional
429-
parameters supported by the ``scaleImage`` function from ``plone.scale``,
430-
e.g. ``mode`` or ``quality``.
431-
432-
.. _`plone.scale`: https://pypi.org/project/plone.scale/
433-
434-
2. for automatic tag generation with extra parameters you would use::
435-
436-
<img tal:define="images context/@@images"
437-
tal:replace="structure python: images.tag('image',
438-
width=1200, height=800, mode='contain')" />
439-
440-
3. It is possible to access scales via predefined named scale sizes, rather
441-
than hardcoding the dimensions every time you access a scale. The scale
442-
sizes are found via calling a utility providing
443-
``plone.namedfile.interfaces.IAvailableSizes``, which should return a dict of
444-
scale name => (width, height). A scale called 'mini' could then be accessed
445-
like this::
446-
447-
<img tal:define="images context/@@images"
448-
tal:replace="structure python: images.tag('image', scale='mini')" />
449-
450-
This would use the predefined scale size "mini" to determine the desired
451-
image dimensions, but still allow to pass in extra parameters.
452-
453-
4. a convenience short-cut for option 3 can be used::
454-
455-
<img tal:replace="structure context/@@images/image/mini" />
456-
457-
5. and lastly, the short-cut can also be used to render the unscaled image::
458-
459-
<img tal:replace="structure context/@@images/image" />
460-
461-
462-
Image scales and srcset
463-
-----------------------
464-
465-
Nowadays modern browsers are able to render different images depending on their width
466-
if URLs and widths are correctly provided in an attribute called ``srcset``, and the rendered
467-
space is provided in the attribute ``sizes``.
468-
469-
So one can do the following:
470-
471-
.. code-block:: xml
472-
473-
<img tal:define="images context/@@images;"
474-
tal:replace="structure python:images.srcset(sizes='90vw')" />
475-
476-
477-
This will render the ``img`` with the URLs of all scales configured in Plone, calculating the width
478-
of each of the scales and will add the ``sizes="90vw"`` attribute.
479-
The ``sizes`` attribute instructs the browser to render
480-
the image that best fits, as it will take 90% of the current viewport width.
481-
482-
This means that, for bigger screens, the browser will download a bigger scaled image, while for smaller screens, a smaller scaled image is enough.
483-
484-
This also means that the developer does not need to worry about creating a specific scale.
485-
They only need to provide the correct media query to signal the required width.
486-
487-
The ``scrset`` method of the ``@@images`` view also takes all other parameters that can be rendered in the ``img`` tag, such as ``title``, ``alt``, or ``loading``:
488-
489-
.. code-block:: xml
490-
491-
492-
<img tal:define="images context/@@images;"
493-
tal:replace="structure python:images.srcset(sizes='90vw',
494-
alt='This is the alternative text',
495-
loading='lazy',
496-
css_class='rounded-img')" />
497-
498-
499-
.. note::
500-
501-
While using this approach may be useful for projects, using it in reusable add-ons is not recommended, because it may require overriding it to your needs in a project.
502-
For such cases, use configurable picture variants instead.

0 commit comments

Comments
 (0)