slimdeer README

README проекта с github.com/heydeer/slimdeer. Одним файлом markdown: README.md.

slimdeer

Smaller images. Same picture. slimdeer makes PNG and JPEG images smaller, or turns them into WebP and AVIF, with no quality slider: for each image it searches for the smallest file whose perceptual score still reaches a target picked for that image. A PNG becomes the palette PNG that does (palette sizes from 2 to 256 colors, with and without dithering): at the same quality, the median image comes out 8–12% smaller than with TinyPNG, the best result of any open-source compressor we've measured. slimdeer was called pngdeer until version 0.3.0.

Try it in your browser → Nothing is uploaded: images are compressed on your device.

slimdeer in the browser

brew install heydeer/tap/slimdeer
slimdeer logo.png photo.jpg    # writes logo.min.png and photo.min.jpg

Leaderboard

We ran slimdeer, TinyPNG and eight open-source quantizers on 180 PNGs: icons, UI screenshots, illustrations, photos, cut-outs and 3D renders. Every output was scored against its original with SSIMULACRA2, a perceptual metric where 90 means indistinguishable at 1:1. TinyPNG is the yardstick:

Each cell gives the held-out set (71 images) / the tuning set (109 images):

Compressor Points Reaches
slimdeer +1.7 / +2.0 67 / 106
TinyPNG (the yardstick) 0 71 / 109
pngquant 0.0 / +0.3 53 / 87
quantizr −0.1 / −1.0 39 / 53
exoquant −3.7 / −5.1 19 / 24
NeuQuant −6.5 / −9.8 4 / 5
FFmpeg −7.0 / −8.8 16 / 15
quantette −7.6 / −9.6 18 / 21
ImageMagick −11.3 / −14.5 3 / 8
Pillow −16.8 / −19.5 4 / 4

At TinyPNG's quality, slimdeer's files are 12% smaller on the held-out set and 8% smaller on the tuning set (median image).

WebP

slimdeer also writes WebP (an output name ending in .webp, or the switch in the browser): the smaller of its palette image stored losslessly and the lowest lossy quality that keeps the target (a JPEG photo: below). Against TinyPNG's WebP on 120 of the images, the size each tool needs to match TinyPNG's quality (median image / in total), and how many images it can bring up to that quality:

Compressor Size at TinyPNG's quality Reaches
slimdeer 95.0% / 93.9% 118
TinyPNG (the yardstick) 100% 120
cwebp, best of 27 settings 97.9% / 110.2% 120
pngquant + cwebp, best of 10 135.0% / 212.1% 115

JPEG

slimdeer also takes JPEG photos (slimdeer photo.jpg -o smaller.jpg, or drop them in the browser) and writes a smaller JPEG: re-encoded with mozjpeg at the lowest quality that keeps the target, never bigger than the photo. On 60 photos from Wikimedia Commons, 30 web-size copies and 30 camera originals, the size each tool needs to match TinyPNG's quality (median photo / in total), and how many photos it can bring up to that quality:

Compressor Size at TinyPNG's quality Reaches
slimdeer 87.8% / 85.4% 60
TinyPNG (the yardstick) 100% 60
jpegli, best of 12 settings 89.2% / 87.2% 60
mozjpeg, best of 7 qualities 94.2% / 89.1% 59

AVIF

slimdeer also writes AVIF (an output name ending in .avif, or the switch in the browser), from PNGs and JPEG photos: libaom's lowest quality that keeps the target as Chrome shows the file. On 54 images, 30 of the photos above and 24 PNGs of every kind, every file decoded by Chrome, the size each tool needs to match TinyPNG's AVIF's quality (median image / in total), and how many images it can bring up to that quality:

Compressor Size at TinyPNG's quality Reaches
slimdeer 77.4% / 78.1% 54
TinyPNG (the yardstick) 100% 54
avifenc, best of 33 settings 89.3% / 83.3% 54
rav1e, best of 11 qualities 102.0% / 97.3% 54

How it works

The research notes follow every step, from the first comparison with TinyPNG to today's defaults.

Command line

slimdeer photo.jpg                 # photo.min.jpg, at a quality picked for it
slimdeer *.png -d dist             # dist/NAME.png for each
slimdeer -r assets -d dist         # every PNG and JPEG under assets, into the same folders under dist
slimdeer logo.png --format webp    # logo.min.webp (also avif; from a PNG or a JPEG)
slimdeer in.png -o out.avif        # out.avif, the format as its name says
slimdeer shot.png --target 90      # a fixed SSIMULACRA2 score: 90 looks lossless, 70 is high quality
slimdeer - < in.png > out.png      # stdin to stdout
slimdeer --help

Like cp, it says nothing unless something goes wrong: -v says what each file came to, and --json prints each file's report, a JSON line per file. A file that fails doesn't stop the others (slimdeer then exits 1). A name it makes up never replaces an input; -o can. With -r, a folder stands for the PNGs and JPEGs in it and every folder below it: hidden ones, linked folders, earlier NAME.min.EXT outputs and a -d folder inside it are left out, so running it again on the same folder doesn't compress them twice. Two inputs that would get the same output name are reported, not written over each other.

From source: cargo build --release, and the binary is target/release/slimdeer.

Browser

The web app runs the same code compiled to WebAssembly. To run it locally (web/build.sh lists the toolchain it needs):

sh web/build.sh
python3 web/serve.py   # http://localhost:8770

License

MIT. Dependencies keep their own licenses (web/THIRD_PARTY_LICENSES.txt), as do the test and sample images (the SOURCES.md next to them). JPEG output is encoded with mozjpeg: this software is based in part on the work of the Independent JPEG Group. AVIF output is encoded with libaom.

slimdeer (heydeer/slimdeer)

Ищем в базе…

Что это такое?pngdeer — это PNG-компрессор с потерями, который автоматически перебирает размеры палитры от 2 до 256 цветов и варианты дизеринга, оценивает каждый результат перцептивной метрикой (SSIMULACRA2) и оставляет самый маленький файл, который при этом выглядит правильно. Выставлять качество вручную не нужно — ползунка качества нет.
Это инструмент командной строки, приложение для браузера или и то и другое?И то и другое. Один и тот же код на Rust работает как нативная CLI-программа на macOS и Linux и также компилируется в WebAssembly для версии в браузере, создавая одинаковые выходные файлы.
Как его запустить?Соберите CLI из исходников командой 'cargo build --release'; готовый бинарник появится в target/release/pngdeer. Приложение для браузера можно использовать прямо онлайн или запустить локально, используя инструменты, перечисленные в web/build.sh.
Нужно ли устанавливать Rust, чтобы им пользоваться?Чтобы собрать CLI из исходников, нужны Rust и Cargo, так как в README описана только сборка из исходного кода. Для версии в браузере ничего, кроме самого браузера, не требуется, поскольку она поставляется в виде WebAssembly.
Могу ли я сам задать качество сжатия?Нет, ползунка качества нет: pngdeer всегда ориентируется примерно на то, что получилось бы у TinyPNG для этого изображения, и ограничивает результат значением 90 по шкале SSIMULACRA2, так что сделать его выше или ниже нельзя.
Работает ли инструмент командной строки и на Windows?В README для CLI указаны только macOS и Linux, Windows не упоминается, поэтому для Windows лучше использовать версию в браузере (WebAssembly).
Загружает ли версия для браузера мои изображения куда-нибудь?Нет, изображения сжимаются полностью на вашем устройстве; ничего не отправляется на сервер.
Насколько файлы меньше, чем у TinyPNG?На тесте из 180 изображений файлы pngdeer оказались на 8–12% меньше, чем у TinyPNG, при одинаковом качестве для медианного изображения, а при проверке другой метрикой (butteraugli), которую поиск вообще не использует, — всё ещё на 6–9% меньше.
Как pngdeer выбирает палитру, а не использует фиксированную настройку?Для каждого изображения он пробует размеры палитры от 2 до 256 цветов, с дизерингом Флойда–Штейнберга и без него, а также с парой других вариантов, оценивает каждый кандидат по SSIMULACRA2 в цветовом пространстве Oklab и оставляет самый маленький файл, который всё ещё проходит порог качества.
Как он работает быстро на больших изображениях?Поиск палитры выполняется на уменьшенной превью-копии, а выбранные настройки проверяются только на полном размере. Версия для браузера обрабатывает изображения до 40 мегапикселей; CLI может работать с большими.
Какие есть похожие проекты?lightcraft, liteparse, genact, pdfcraft, spritefusion-sprite-normals, xerj, TurboBench, photosuite
Автор
heydeer
Размер
77.6 MB
Звёзды
566
Обновлён
КоммитNov 04
Возраст
24 д
Коммиты · 90 дней