Is it possible in HTML to define some tag structure so that one image
file (of more than one possible) to be selected?
<picture>
<source srcset="z.gif">
<img src="z.jpg" alt="the image">
</picture>
I've seen such code in cases with media="(min-width:650px)", i.e. size depending image selections[*] - so it is possible to select depending
on the window size at least -,
(There are probably workarounds[**] that I want to avoid if possible
or if there's a cleaner way to handle that, with <picture> or else.)
Janis Papanagnou wrote:
Is it possible in HTML to define some tag structure so that one image
file (of more than one possible) to be selected?
In a way, yes, but not the way you want, IrCOm afraid.
<picture>
<source srcset="z.gif">
<img src="z.jpg" alt="the image">
</picture>
It seems (I only tested on Chrome and Edge) that browsers handle the
absence of z.gif awkwardly: instead of graceful degradation to rendering
the img element, they just render a broken image icon and the alt text!
I've seen such code in cases with media="(min-width:650px)", i.e. size
depending image selections[*] - so it is possible to select depending
on the window size at least -,
This works indeed. If you set, say, media="max-width=10000px" (a
condition that will hardly be fulfilled in your environment), then
browsers fall back to rendering the image specified in the img element.
So the selection mechanism works for media queries, but not regarding
the success of rendering the image given in the source element.
(There are probably workarounds[**] that I want to avoid if possible
or if there's a cleaner way to handle that, with <picture> or else.)
I think the proper approach is to check server-side (using whatever server-side tools you have) whether an image exist and serve either it
or a substitute image.
Janis Papanagnou wrote:
Is it possible in HTML to define some tag structure so that one image
file (of more than one possible) to be selected?
I just found an approach on the Web that seems to work for me:
<img
src="z.gif"
onerror="this.onerror=null; this.src='z.jpg'"
/>
Janis Papanagnou wrote:
I just found an approach on the Web that seems to work for me:
<img
src="z.gif"
onerror="this.onerror=null; this.src='z.jpg'"
/>
Using client-side JavaScript is indeed an option, but I mentioned
server-side solutions, as they are more robust, when they can be used.
If this is really about image formats (like GIF vs. JPEG), it looks like
a candidate for content negotiation. You could use src="z" and let the
server map this to a suitable format alternative.
I've read about Browsers being able to identify image file types, but
in these contexts they wrote something that it would be an unreliable
method. (I know far to few about this area to judge, so I abstained
from taking that path.)
Is it possible in HTML to define some tag structure so that one image
file (of more than one possible) to be selected? For example if I have
EITHER file z.jpg OR z.gif (but not both!) and I want to display the
actually existing image (instead of getting a broken link).
I played around with <picture>/<source>[*] (but that wasn't working as desired)
<picture>
<source srcset="z.gif">
<img src="z.jpg" alt="the image">
</picture>
I've seen such code in cases with media="(min-width:650px)", i.e. size depending image selections[*] - so it is possible to select depending
on the window size at least -, and I hoped such <picture> definitions
might also work with the simple selection case I have.
Any hints?
(There are probably workarounds[**] that I want to avoid if possible
or if there's a cleaner way to handle that, with <picture> or else.)
Janis
[*] https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_picture
[**] E.g. (a) converting the data, all image files to one type, or (b)
use a generic name for the file, say 'z' (without extension), and let
the browser interpret it; I read that browsers don't mind the type.
*How to load different image formats according to browser support using HTML?*
[snip link]
On 14.05.2023 15:49, Walter Brill wrote:
*How to load different image formats according to browser support using
HTML?*
[snip link]
Behind that link I see a chatGPT window and the requirement to login
and an Advertisement area. - Two thumbs down. Thanks for the try. - J.
On 14.05.2023 15:49, Walter Brill wrote:
*How to load different image formats according to browser support using
HTML?*
[snip link]
Behind that link I see a chatGPT window and the requirement to login
and an Advertisement area. - Two thumbs down. Thanks for the try. - J.
Is it possible in HTML to define some tag structure so that one image
file (of more than one possible) to be selected? For example if I have
EITHER file z.jpg OR z.gif (but not both!) and I want to display the
actually existing image (instead of getting a broken link).
I played around with <picture>/<source>[*] (but that wasn't working as desired)
<picture>
<source srcset="z.gif">
<img src="z.jpg" alt="the image">
</picture>
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 02:48:16 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
10 files (20,373K bytes) |
| Messages: | 264,422 |