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
2. The Trade-off: Artifacts (Lossy)
Drag the slider to permanently delete data from the image to save space.
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?
return mass * 9.81
print("System Loaded")
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)
"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)
Python Scripts (Recommendation): The developer MUST use Lossless compression for the Python programming scripts.
Python Scripts (Justification): If Lossy compression were used, it would permanently delete characters/lines of code. This would instantly cause syntax errors and render the program completely broken upon decompression.
Nature Photos (Recommendation): The developer should use Lossy compression (like JPEG) for the high-definition nature photos.
Nature Photos (Justification): Lossy compression creates a significantly smaller file, which solves the strict bandwidth constraints. The data permanently unrecoverable (e.g. slight colour blending in a blue sky) will not be noticeable to the human eye, maintaining an acceptable level of quality.