From b4b394c99cf81c36f0a35f89ee4d7349fe344a50 Mon Sep 17 00:00:00 2001
From: Mikel Larreategi
+ srcst allows the browser selecting the correct image depending on the space the image has on a page. +
++ To do so, the @@images view provides a srcset method, that will output the full srcset of this image, using all available image scales. It has a required paramter the value of the sizes attribute that the user of this method has to provide and will be outputed as is in the generated HTML. +
+
+
+
+
+
+
+
Go to: +<<<<<<< HEAD +======= + examples, + cover, + contain, + picture tags, + img tag with srcset, + stored scales, + clear +
+Standard display of Image content type, but using thumb scale
+Go to: -<<<<<<< HEAD picture tags, + img tag with srcset,
-======= - examples, - cover, - contain, - picture tags, - img tag with srcset, - stored scales, - clear - -Standard display of Image content type, but using thumb scale
-- srcst allows the browser selecting the correct image depending on the space the image has on a page. -
-- To do so, the @@images view provides a srcset method, that will output the full srcset of this image, using all available image scales. It has a required paramter the value of the sizes attribute that the user of this method has to provide and will be outputed as is in the generated HTML. -
-
-
-
-
-
-
-
+
srcst allows the browser selecting the correct image depending on the space the image has on a page.
-
- To do so, the @@images view provides a srcset method, that will output the full srcset of this image, using all available image scales. It has a required paramter the value of the sizes attribute that the user of this method has to provide and will be outputed as is in the generated HTML.
-
-
- img with srcset attributes
+
-
-
-
-
+ To do so, the @@images view provides a srcset method, that will output the full srcset of this image, using all available image scales. It has a required parameter the value of the sizes attribute that the user of this method has to provide and will be outputted as is in the generated HTML. +
+
+
+
+
+
+
+
- To do so, the @@images view provides a srcset method, that will output the full srcset of this image, using all available image scales. It has a required parameter the value of the sizes attribute that the user of this method has to provide and will be outputted as is in the generated HTML. + To do so, the @@images view provides a srcset method, that will output the full srcset of this image, using all available image scales. It has as required parameter the value of the sizes attribute that the user of this method has to provide and will be output as is in the generated HTML.
- srcst allows the browser selecting the correct image depending on the space the image has on a page.
+ srcset allows the browser to select the correct image, depending on the space the image has on a page.
To do so, the @@images view provides a srcset method, that will output the full srcset of this image, using all available image scales. It has as required parameter the value of the sizes attribute that the user of this method has to provide and will be output as is in the generated HTML.
From 681facdda1384119bb0c250ed3428165037b7b88 Mon Sep 17 00:00:00 2001
From: Mikel Larreategi
srcset allows the browser to select the correct image, depending on the space the image has on a page.
+
To do so, the @@images view provides a srcset method, that will output the full srcset of this image, using all available image scales. It has as required parameter the value of the sizes attribute that the user of this method has to provide and will be output as is in the generated HTML.
From 85ecca37d38d583ce543b34ac2c72152b56c8f32 Mon Sep 17 00:00:00 2001
From: Mikel Larreategi
From 08fe009827d9900589fcd337fe2b4ba3f261eb05 Mon Sep 17 00:00:00 2001
From: Mikel Larreategi
img with srcset attributes
"""
+ expected = f"""
"""
self.assertTrue(_ellipsis_match(expected, tag.strip()))
From 10a4ac34b003c0ba53b296cf93b6ef524165dc78 Mon Sep 17 00:00:00 2001
From: Mikel Larreategi
+
+
+Image scales and srcset
+-----------------------
+
+Nowadays modern browsers are able to render different images depending on their width
+if urls and widths are correctly provided in an attribute called `srcset` and the rendered
+space is provided in the attribute `sizes`.
+
+So one can do the following:
+
+
+
+
+This will render the `img` with the urls of all scales configured in Plone, calculating the width
+of each of the scales and will add the `sizes="90vw"` attribute which instructs the browser to "render
+the image that best fits as it will take the 90% of the current viewport-width" whichever is the current
+viewport.
+
+This will mean that for bigger screens the browser will download a bigger image while in small screens
+a smaller scale is enough.
+
+This also means that the developer does not need to worry on creating a specific scale, they only need to
+provide the correct media query to signal the required width.
+
+The `scrset` method of the `@@images` view takes also all other parameters that can be rendered in the `img`
+tag such as `title`, `alt` or `loading`:
+
+
+
+
+
+*NOTE*: while using this approach may be useful for projects, using it in reusable addons is not recomended
+because it may require overriding it to your needs in a project. For such cases, we recomend using configurable
+picture variants.
From 2dc84ba56c9b63688583d337855bdd8e3901e394 Mon Sep 17 00:00:00 2001
From: Mikel Larreategi
@@ -475,17 +477,16 @@ So one can do the following:
This will render the ``img`` with the URLs of all scales configured in Plone, calculating the width
of each of the scales and will add the ``sizes="90vw"`` attribute.
The ``sizes`` attribute instructs the browser to render
-the image that best fits as it will take the 90% of the current viewport-width" whichever is the current
-viewport.
+the image that best fits, as it will take 90% of the current viewport width.
+
+This means that, for bigger screens, the browser will download a bigger scaled image, while for smaller screens, a smaller scaled image is enough.
-This will mean that for bigger screens the browser will download a bigger image while in small screens
-a smaller scale is enough.
+This also means that the developer does not need to worry about creating a specific scale.
+They only need to provide the correct media query to signal the required width.
-This also means that the developer does not need to worry on creating a specific scale, they only need to
-provide the correct media query to signal the required width.
+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``:
-The `scrset` method of the `@@images` view takes also all other parameters that can be rendered in the `img`
-tag such as `title`, `alt` or `loading`:
+.. code-block:: xml
-*NOTE*: while using this approach may be useful for projects, using it in reusable addons is not recommended
-because it may require overriding it to your needs in a project. For such cases, we recommend using configurable
-picture variants.
+.. note::
+
+ 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.
+ For such cases, use configurable picture variants instead.
From 0a6f4e0aa2962dc4847e75cafc748a8bd12ee70e Mon Sep 17 00:00:00 2001
From: Mikel Larreategi
-
- This would create an up to 64 by 64 pixel scaled down version of the image
- stored in the "image" field. It also allows for passing in additional
- parameters supported by the ``scaleImage`` function from ``plone.scale``,
- e.g. ``mode`` or ``quality``.
-
- .. _`plone.scale`: https://pypi.org/project/plone.scale/
-
-2. for automatic tag generation with extra parameters you would use::
-
-
-
-3. It is possible to access scales via predefined named scale sizes, rather
- than hardcoding the dimensions every time you access a scale. The scale
- sizes are found via calling a utility providing
- ``plone.namedfile.interfaces.IAvailableSizes``, which should return a dict of
- scale name => (width, height). A scale called 'mini' could then be accessed
- like this::
-
-
-
- This would use the predefined scale size "mini" to determine the desired
- image dimensions, but still allow to pass in extra parameters.
-
-4. a convenience short-cut for option 3 can be used::
-
-
-
-5. and lastly, the short-cut can also be used to render the unscaled image::
-
-
-
-
-Image scales and srcset
------------------------
-
-Nowadays modern browsers are able to render different images depending on their width
-if URLs and widths are correctly provided in an attribute called ``srcset``, and the rendered
-space is provided in the attribute ``sizes``.
-
-So one can do the following:
-
-.. code-block:: xml
-
-
-
-
-This will render the ``img`` with the URLs of all scales configured in Plone, calculating the width
-of each of the scales and will add the ``sizes="90vw"`` attribute.
-The ``sizes`` attribute instructs the browser to render
-the image that best fits, as it will take 90% of the current viewport width.
-
-This means that, for bigger screens, the browser will download a bigger scaled image, while for smaller screens, a smaller scaled image is enough.
-
-This also means that the developer does not need to worry about creating a specific scale.
-They only need to provide the correct media query to signal the required width.
-
-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``:
-
-.. code-block:: xml
-
-
-
-
-
-.. note::
-
- 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.
- For such cases, use configurable picture variants instead.
From 60e3642d22e2ca8a63e5a6768d1547a5a8e30c93 Mon Sep 17 00:00:00 2001
From: Mikel Larreategi
"""
+ expected = f"""
"""
self.assertTrue(_ellipsis_match(expected, tag.strip()))
def testImgSrcSetCustomSrc(self):
@@ -850,7 +850,7 @@ def testImgSrcSetCustomSrc(self):
}
tag = self.scaling.srcset("image", sizes="50vw", scale_in_src="mini")
base = self.item.absolute_url()
- expected = f"""
"""
+ expected = f"""
"""
self.assertTrue(_ellipsis_match(expected, tag.strip()))
def testImgSrcSetInexistentScale(self):
@@ -874,7 +874,7 @@ def testImgSrcSetInexistentScale(self):
"image", sizes="50vw", scale_in_src="inexistent-scale-name"
)
base = self.item.absolute_url()
- expected = f"""
"""
+ expected = f"""
"""
self.assertTrue(_ellipsis_match(expected, tag.strip()))
def testImgSrcSetCustomTitle(self):
@@ -894,7 +894,7 @@ def testImgSrcSetCustomTitle(self):
}
tag = self.scaling.srcset("image", sizes="50vw", title="My Custom Title")
base = self.item.absolute_url()
- expected = f"""
"""
+ expected = f"""
"""
self.assertTrue(_ellipsis_match(expected, tag.strip()))
def testImgSrcSetAdditionalAttributes(self):
@@ -921,6 +921,7 @@ def testImgSrcSetAdditionalAttributes(self):
loading="lazy",
)
base = self.item.absolute_url()
+
expected = f"""
"""
self.assertTrue(_ellipsis_match(expected, tag.strip()))