Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,005 --> 00:00:03,001
- Sometimes, we want to display a big, beautiful,
2
00:00:03,001 --> 00:00:06,006
high resolution image for people with big screens
3
00:00:06,006 --> 00:00:09,001
and then, shrink it way down for people
4
00:00:09,001 --> 00:00:11,007
on phones, on small screens.
5
00:00:11,007 --> 00:00:13,004
CSS can do this.
6
00:00:13,004 --> 00:00:17,002
One image file can be shown at any size.
7
00:00:17,002 --> 00:00:19,000
But there's a problem.
8
00:00:19,000 --> 00:00:22,008
A big, high resolution image contains millions of pixels.
9
00:00:22,008 --> 00:00:25,009
And all that data can make the file size pretty big.
10
00:00:25,009 --> 00:00:27,008
Which takes a lot of time to download
11
00:00:27,008 --> 00:00:29,004
on a slow network connection
12
00:00:29,004 --> 00:00:31,001
and can use up people's data plans
13
00:00:31,001 --> 00:00:34,007
and in some markets, cost them a lot of money.
14
00:00:34,007 --> 00:00:36,009
We don't want to deliver unneeded
15
00:00:36,009 --> 00:00:40,001
high resolution data to small screens.
16
00:00:40,001 --> 00:00:42,006
Instead, maybe we should just make
17
00:00:42,006 --> 00:00:44,006
all of our images much, much smaller.
18
00:00:44,006 --> 00:00:48,000
Physically smaller, less colored data, fewer pixels,
19
00:00:48,000 --> 00:00:52,003
more compressed, that will work well for a smaller screen.
20
00:00:52,003 --> 00:00:55,000
But then if we send that file to everybody,
21
00:00:55,000 --> 00:00:57,004
people with big desktop monitors
22
00:00:57,004 --> 00:01:00,009
won't get to see a large, glorious photo.
23
00:01:00,009 --> 00:01:04,001
They'll get a low quality photo blown up really big.
24
00:01:04,001 --> 00:01:06,009
Or our web designs are limited to keeping every image
25
00:01:06,009 --> 00:01:09,004
physically really small.
26
00:01:09,004 --> 00:01:12,000
So, what can we do?
27
00:01:12,000 --> 00:01:14,006
Well, we can use the power of HTML
28
00:01:14,006 --> 00:01:19,001
to deliver different image files to different size screens.
29
00:01:19,001 --> 00:01:21,006
We can make several different files and list them
30
00:01:21,006 --> 00:01:23,009
as a set of options in our HTML
31
00:01:23,009 --> 00:01:27,001
and let the browser decide which image to download.
32
00:01:27,001 --> 00:01:29,007
It can do so in coordination with the operating system
33
00:01:29,007 --> 00:01:32,000
while taking the device hardware capabilities
34
00:01:32,000 --> 00:01:35,000
and the network speed into account as well.
35
00:01:35,000 --> 00:01:37,003
Let's first start with the basic code
36
00:01:37,003 --> 00:01:39,001
for loading an image on the page.
37
00:01:39,001 --> 00:01:41,008
I have an image element with a source attribute
38
00:01:41,008 --> 00:01:44,006
that points to an image file with the alt text
39
00:01:44,006 --> 00:01:45,008
and the width and the height.
40
00:01:45,008 --> 00:01:46,009
Just like we talked about
41
00:01:46,009 --> 00:01:49,004
when I first introduced the image element.
42
00:01:49,004 --> 00:01:52,002
You can see here that I wrote 480,
43
00:01:52,002 --> 00:01:54,004
in the big white text on the image itself.
44
00:01:54,004 --> 00:01:56,009
So it's obvious which image has loaded when.
45
00:01:56,009 --> 00:02:00,002
Now, this image is 480 pixels wide.
46
00:02:00,002 --> 00:02:04,000
And it will look good when it's displayed at 480 pixels
47
00:02:04,000 --> 00:02:06,006
or smaller on some devices.
48
00:02:06,006 --> 00:02:10,002
More and more screen these days however, are not 1X screens.
49
00:02:10,002 --> 00:02:14,006
The retina screens, high density, DPI, super retina,
50
00:02:14,006 --> 00:02:17,003
ultra fancy billions of whatever the latest name is
51
00:02:17,003 --> 00:02:19,004
for these amazing screens.
52
00:02:19,004 --> 00:02:21,003
Basically, there are a bunch of screens out there
53
00:02:21,003 --> 00:02:25,005
with a pixel density, is 2X, 3X, 4X
54
00:02:25,005 --> 00:02:28,009
where more data can be displayed by the screen.
55
00:02:28,009 --> 00:02:31,009
Right now, my older computer has a 1X screen.
56
00:02:31,009 --> 00:02:34,001
My newer computer has a 2X screen.
57
00:02:34,001 --> 00:02:36,009
I think my phone has a 3X screen
58
00:02:36,009 --> 00:02:39,006
and I'm not really sure what the rest of my devices are.
59
00:02:39,006 --> 00:02:42,005
I just know that I want photos to look good.
60
00:02:42,005 --> 00:02:44,007
The simplest way to support these different screens
61
00:02:44,007 --> 00:02:46,009
is to create multiple copies of our image
62
00:02:46,009 --> 00:02:49,009
in different resolutions and then tell the browser
63
00:02:49,009 --> 00:02:54,001
that those copies are available.
64
00:02:54,001 --> 00:02:56,007
The device can then decide what it wants to do.
65
00:02:56,007 --> 00:02:59,002
The browser will look at the screen density,
66
00:02:59,002 --> 00:03:02,000
the network connection, the users settings
67
00:03:02,000 --> 00:03:04,002
and decide which image to use.
68
00:03:04,002 --> 00:03:06,003
Even if someone has a high resolution screen,
69
00:03:06,003 --> 00:03:08,002
the browser might decide to download
70
00:03:08,002 --> 00:03:10,009
a lower resolution image.
71
00:03:10,009 --> 00:03:13,004
I've created four copies of this photo
72
00:03:13,004 --> 00:03:19,003
at 480, and 960, 1440 and 1920 pixels wide.
73
00:03:19,003 --> 00:03:22,008
Let me duplicate this basic HTML for displaying an image.
74
00:03:22,008 --> 00:03:26,009
So we can change the second one and compare the results.
75
00:03:26,009 --> 00:03:28,002
We're going to still write the code
76
00:03:28,002 --> 00:03:30,003
for displaying the image in a normal way.
77
00:03:30,003 --> 00:03:32,003
This is good for older browsers.
78
00:03:32,003 --> 00:03:34,001
We need the source attribute
79
00:03:34,001 --> 00:03:37,001
and we'll put our 1X version of the image here.
80
00:03:37,001 --> 00:03:38,009
We need the alt text just like before
81
00:03:38,009 --> 00:03:40,004
and the width and the height.
82
00:03:40,004 --> 00:03:44,001
It will definitely still improve in performance, keep that.
83
00:03:44,001 --> 00:03:47,004
It's OK that the pixel numbers won't always be accurate.
84
00:03:47,004 --> 00:03:49,001
The aspect ratio is what's important here.
85
00:03:49,001 --> 00:03:53,004
And 480 by 360 calculates to a four by three aspect ratio.
86
00:03:53,004 --> 00:03:55,007
All of these photos are four by three.
87
00:03:55,007 --> 00:03:58,003
Now, let's add a source set attribute.
88
00:03:58,003 --> 00:04:00,004
Inside of it, we'll list the images
89
00:04:00,004 --> 00:04:02,009
that we are offering the browser as choices.
90
00:04:02,009 --> 00:04:04,009
It's a comma separated list.
91
00:04:04,009 --> 00:04:09,007
With a URL to a file, a space, the resolution,
92
00:04:09,007 --> 00:04:13,008
like 2X, 3X, 4X, 1.5X, whatever,
93
00:04:13,008 --> 00:04:16,002
a comma, and the next one.
94
00:04:16,002 --> 00:04:17,007
Now, the browser will swap out
95
00:04:17,007 --> 00:04:19,007
one version of this image for another
96
00:04:19,007 --> 00:04:22,005
based on what it thinks is best.
97
00:04:22,005 --> 00:04:25,008
This is a great solution for providing different size images
98
00:04:25,008 --> 00:04:28,007
to handle retina and high DPI screens.
99
00:04:28,007 --> 00:04:31,009
But what about handling different size images
100
00:04:31,009 --> 00:04:33,004
based on the layout?
101
00:04:33,004 --> 00:04:36,002
Based on the width of the page?
102
00:04:36,002 --> 00:04:38,000
Let's look at that next.
7675
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.