Skip to content

Commit

Permalink
more work on the post
Browse files Browse the repository at this point in the history
  • Loading branch information
knzai committed Sep 1, 2024
1 parent 74ad659 commit 71aa014
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 9 deletions.
28 changes: 23 additions & 5 deletions _drafts/2024-08-31-ccc-svg.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
---
layout: post
title: "SVG-CCC: SVG cross-codec-compilation"
image: /assets/img/projects/svg-cross-codec-compilation.svg
title: "The holy grail of image formats: SVG cross-codec-compilation vs AVIF"
image: /assets/img/posts/svg-ccc/compilation.svg
description: >
Photo, scalar, and/or vector style compression in the same image for smaller size w/o losing crisp lines
Photos and text or diagrams in the same image file, at a small size, without losing cripsness
---

When using images on the web you've always had to choose between size and quality. This gets particularly pointed when you have one image containing both a photo and crisp lines (for instance text, or a diagram). Compressing both of those in the same image will either require a very large image, or the compression will become apparent, especially around the crisp lines.

You can avoid this by using an SVG as a container for two images Base64 data encoded directly into the same file (ideal for mobile loading with fewer requests to the server, easier maintenance, works in more situations that just layering or compositing two iamges via css).

For instance, here's the header image for this post, originally a 627kb PNG, compressed to a 18kb jpg (a 25% quality setting), to exaggerate the effect beyond what you'd ever typically settle on:

![](/assets/img/posts/svg-ccc/25.jpg)



I started writing this post about using SVG as a container image to composite images with different compression needs. You can acheive small file size, with crisp lines and no JPG compression artifacts, in a single-file that downloads without an extra request to the server, and that scales and
```xml
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image xlink:href="data:image/png;base64,[DATA]"/>
<image xlink:href="data:image/jpg;base64,[DATA]"/>
```
you can have a highly compressed jpeg

While working on getting the [Cloud City site](https://cloudcoty.io) load times a little snappier, particularly on mobile (the only place image size matters that much anymore), I complained how I wished there was an image format that handled both jpg and png compression in the same file. Sure you can position one over the other with css, but having everything in one file is simpler for responsive scaling and optimizing (cutting down the separate file requests).

Then I realized there is such a format: you can composite different images together in an SVG and inline their Base64 encoded data so it's all one file.

This is what one of the header images from the company blog would look like when it has text and an image together in one. It's encoded as a png to keep everything crisp, and clocks in at 668kb:
![](/assets/img/posts/cross-codec-compilation.png)
![](/assets/img/posts/svg-ccc/original.png)

If you just encode the whole thing to an AVIF, for a better file-size, since it has a photo you get the following 13kb image:
There's a tradeoff of size verus quality and it
![](/assets/img/posts/cross-codec-compilation.avif)

For this image, the quality loss on the text is a little more neglible, just making the text a little fuzzy, but on an image with more complicated diagrams it can look worse.
Binary file removed assets/img/posts/cross-codec-compilation-bg.avif
Binary file not shown.
Binary file removed assets/img/posts/cross-codec-compilation-text.png
Binary file not shown.
Binary file removed assets/img/posts/cross-codec-compilation.avif
Binary file not shown.
Binary file removed assets/img/posts/cross-codec-compilation.jpg
Binary file not shown.
Binary file removed assets/img/posts/cross-codec-compilation.png
Binary file not shown.
Binary file added assets/img/posts/svg-ccc/25.avif
Binary file not shown.
Binary file added assets/img/posts/svg-ccc/25.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions assets/img/posts/svg-ccc/compilation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/posts/svg-ccc/lossless.avif
Binary file not shown.
Binary file added assets/img/posts/svg-ccc/lossless.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/posts/svg-ccc/original.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions assets/img/posts/svg-cross-codec-compilation.svg

This file was deleted.

0 comments on commit 71aa014

Please sign in to comment.