Images, Alt Text and Credit Lines
Resize and compress photos so pages load fast, write useful alt text, and credit other people's pictures with the Title, Author, Source, Licence rule, with a worked example of real file sizes.
In this lesson you will
- Resize and compress images sensibly
- Write helpful alt text
- Credit Creative Commons pictures with TASL
- Know the privacy and copyright cautions
About 24 minutes
Priya’s photos make the page slow
Priya adds a photo of her seed tray, straight from her phone. The page now takes far longer to load, and a friend on a slow connection gives up. Pictures make a blog come alive, and they can also make it heavy, inaccessible and legally risky. This lesson covers three things every blogger needs: sizing images so pages load quickly, describing them so that everyone can use them, and using other people’s pictures properly.
Size and quality
A photo from a phone can be four thousand pixels wide, far more than any blog column shows. Large files slow the page, and slow pages lose readers, especially on phones and slow connections. The remedy is to resize the image to about the width it will be displayed, and to save it at a sensible quality. The program below makes a synthetic 1,600 by 900 pixel picture, a stand-in for a photo, since the sizes depend on the picture. It saves the same image at four JPEG quality settings, resizes it to 800 pixels wide and measures the files on disk.
import os, tempfile, re
import numpy as np
from PIL import Image
rng = np.random.default_rng(3)
h, w = 900, 1600
y, x = np.mgrid[0:h, 0:w]
base = np.stack([60 + 100 * x / w, 120 + 80 * y / h, 70 + 40 * np.sin(x / 90.0)], axis=2)
noise = rng.normal(0, 12, (h, w, 3))
img = Image.fromarray(np.clip(base + noise, 0, 255).astype("uint8"))
d = tempfile.mkdtemp()
sizes = {}
for q in (95, 85, 75, 60):
p = os.path.join(d, f"photo_q{q}.jpg")
img.save(p, quality=q)
sizes[q] = os.path.getsize(p) // 1024
print(f"quality {q}: {sizes[q]} KB")
small = img.resize((800, 450))
p = os.path.join(d, "photo_800.jpg")
small.save(p, quality=85)
print("800 px wide at 85:", os.path.getsize(p) // 1024, "KB")
print("saving from 95 to 85:", round(100 * (1 - sizes[85] / sizes[95])), "%")
print("pixels kept at 800 wide:", round(100 * 800 * 450 / (1600 * 900)), "%")
html = '<img src="a.jpg" alt="Seed tray on a sunny windowsill"><img src="b.jpg"><img src="c.jpg" alt="">'
alts = re.findall(r"<img[^>]*>", html)
missing = [a for a in alts if not re.search(r'alt="[^"]+"', a)]
print("images:", len(alts), "without alt text:", len(missing))
def tasl(title, author, source, licence):
return f'"{title}" by {author} ({source}) is licensed under {licence}.'
print(tasl("Seedlings", "A. Gardener", "example.org", "CC BY 4.0"))
quality 95: 783 KB
quality 85: 367 KB
quality 75: 227 KB
quality 60: 140 KB
800 px wide at 85: 44 KB
saving from 95 to 85: 53 %
pixels kept at 800 wide: 25 %
images: 3 without alt text: 2
"Seedlings" by A. Gardener (example.org) is licensed under CC BY 4.0.
At quality 95 the file is 783 KB. At 85 it is 367 KB, a saving of 53 per cent, and the picture is nearly indistinguishable to the eye for most photos. At 75 it falls to 227 KB and at 60 to 140 KB, where artefacts begin to show. Resizing the 85 version to 800 pixels wide, which keeps only 25 per cent of the pixels, brings it to 44 KB. These sizes are for this synthetic picture, which is full of random noise and compresses badly. Real photos usually give smaller files, but the pattern is the same: resizing and sensible quality settings can shrink an image dramatically without a visible loss. Check your blogging tool, which may offer to do this when you upload, and look at the result on a phone.
Alt text for everyone
Alt text is a short written description of an image, kept in the page’s code. Screen readers speak it to people who cannot see the image, it shows when an image fails to load, and search engines use it to understand the picture. The program checked three images in a made-up post and found 2 of 3 had no useful alt text. Write it to say what matters about the picture: ‘Seed tray on a sunny windowsill’ is better than ‘image1’ or an empty description. If an image is purely decoration, an empty alt value is fine, since it tells screen readers to skip it, which is different from forgetting.
Using other people’s pictures
Finding a picture online does not mean you may use it. Most are protected by copyright. Your safest picture is your own. Beyond that you may use pictures that are licensed for reuse, such as Creative Commons licences, or from a stock site whose licence you have read. Every Creative Commons licence requires you to credit the creator, and a handy rule for that credit is TASL: Title, Author, Source, Licence. Some licences add conditions, such as no commercial use or no changes, so read which licence applies. If you change the picture, say so. The last line of the program builds a credit in the TASL form. If you cannot find a clear licence, ask for permission or choose another picture.
- Resize to about the width you need, and save at a sensible quality.
- Give files short, readable names, such as seed-tray.jpg.
- Write alt text for each meaningful image.
- Use your own photos where you can. For others, check the licence and credit properly.
- Check how the page loads on a phone.
Uploading full-size phone photos and trusting the tool to cope. Many tools do not shrink them, and pages become slow. Resize first.
Photos from phones can contain hidden data, including the place where they were taken. Check whether your tool removes it before you publish pictures of your home or other private places, and get permission before showing people who can be recognised. This course is not legal advice, and copyright and privacy rules differ by country.
Practice for this lesson
Check what you learned
Five quick questions. Pick an answer and you will see straight away whether it is right and why.
Why resize photos before uploading?
- Small files are illegal
- Alt text needs it
- Large files slow the page
- Search engines ban big files
Resizing to the displayed width makes pages load faster.
What is alt text?
- A short description of an image
- A caption on the page
- A file name
- A licence
It describes an image for screen readers and other uses.
What does TASL stand for?
- Text, Alt, Size, Link
- Tag, Alt, Slug, Link
- Title, Author, Source, Licence
- Title, Alt, Source, Label
It is a handy checklist for crediting creators.
Does a picture found online mean you may use it?
- No, you must check its licence
- Yes, always
- Only on blogs
- Only if small
Most pictures are protected by copyright.
What is the safest source of pictures?
- A search result
- Your own photos
- A rival blog
- A social feed
Your own photos avoid licence worries.
Summary
- Resize and save at a sensible quality so pages load quickly.
- Write alt text that says what matters about the image.
- Use your own pictures, or check licences and credit with TASL.
- Beware hidden data and permission for people in photos.
Questions
What quality setting should I use?
There is no single answer. Many photos look fine at around 80 to 85 for JPEG. Compare the result on a phone and keep files as small as you can without visible damage.
Do I need alt text on every image?
On every meaningful image, yes. Purely decorative images can have an empty alt value so that screen readers skip them.
Are the file sizes real?
They are real measurements of a synthetic test picture made for the lesson. Your own photos will give different sizes.
