Compression

Reducing file size: Lossy vs Lossless compression.

Think of it like: Packing the Suitcase

You need to fit your clothes into a small carry-on bag.

Lossy (Cutting)

You cut the sleeves off your shirts. It fits! But when you unpack, you can never get the sleeves back. The quality is permanently reduced.

Lossless (Folding)

You use a vacuum bag to squash the air out. It fits! When you unpack, the air comes back and the shirt is perfect again.

Lossy Compression

Permanently removes data to reduce size.

  • Significantly smaller file sizes.
  • Quality is reduced (Pixelation, Artifacts).
  • Examples: JPEG (Images), MP3 (Audio), MP4 (Video).
  • NOT for Text/Code (Can't lose words!).

Lossless Compression

Reduces size without losing ANY data.

  • Original file can be perfectly reconstructed.
  • Less compression capability than Lossy.
  • Examples: ZIP, PNG, FLAC.
  • Essential for Text documents and Code.

The Compression Lab

Experiment with the three core tools to understand the necessity of compression, the reality of visual artifacts, and the strict rules for text files.

1. The Need: Bandwidth & Storage

Select a file type and apply compression to see the massive impact on file sizes and network transmission times.

Transmission Result

File Size: 120.0 GB
Download Time: 2.7 Hours
Data Integrity: Perfect (No Data Lost)

2. The Trade-off: Artifacts (Lossy)

Drag the slider to permanently delete data from the image to save space.

Landscape
No Compression Maximum Deletion

File Size: 12.0 MB

Status: 100% Data Intact

3. The Trap: Lossy on Text

You are compressing a critical block of Python source code to send via email. Which algorithm must you use?

def calculate_gravity(mass):
    return mass * 9.81

print("System Loaded")
Awaiting compression choice...

Check Your Understanding

1. Which type of file should ALWAYS be compressed using a Lossless algorithm?

2. What is the main advantage of Lossy compression over Lossless compression?

3. How does Run Length Encoding (RLE) compress data?

Evaluation Exam Scenario (AO3)

1 / 3

"A web developer is building a website to host Python programming scripts (.py files) alongside high-definition stock photos of nature (.raw). The web host limits bandwidth, so all files must be compressed before uploading. Recommend and justify the specific type of compression (Lossy or Lossless) the developer should use for EACH file type." (4 marks)