Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
1099 lines (940 loc) · 36.3 KB
/
Copy pathindex.html
File metadata and controls
1099 lines (940 loc) · 36.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en" prefix="og: https://ogp.me/ns#">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script>!function () { var e = localStorage.getItem("theme"); e || (e = window.matchMedia("(prefers-color-scheme:dark)").matches ? "dark" : "light"), document.documentElement.className = e }();</script>
<title>Lessbytes — Perceptual Image Compression for Web & CLI</title>
<meta name="title" content="Lessbytes — Perceptual Image Compression for Web & CLI" />
<meta name="description"
content="Compress images in the browser or CLI with no quality guessing. SSIM-guided binary search finds the smallest file that still looks identical to the original." />
<meta name="keywords"
content="lessbytes, image compression, SSIM, WebP, AVIF, JPEG, browser image compression, image optimizer CLI, Dev Chauhan" />
<meta name="author" content="Dev Chauhan" />
<meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1" />
<link rel="canonical" href="https://dqev.github.io/lessbytes/" />
<!-- Favicon -->
<link rel="icon" type="image/svg+xml" href="assets/logo.svg" />
<link rel="apple-touch-icon" href="assets/logo.svg" />
<!-- Theme Meta -->
<meta name="theme-color" content="#121212" />
<meta name="color-scheme" content="dark light" />
<meta name="msapplication-TileColor" content="#121212" />
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:url" content="https://dqev.github.io/lessbytes/" />
<meta property="og:title" content="Lessbytes — Perceptual Image Compression for Web & CLI" />
<meta property="og:description"
content="Compress images in the browser or CLI with no quality guessing. SSIM-guided binary search finds the smallest file that still looks identical to the original." />
<meta property="og:image" content="https://dqev.github.io/lessbytes/assets/og.png" />
<meta property="og:site_name" content="Lessbytes" />
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:url" content="https://dqev.github.io/lessbytes/" />
<meta name="twitter:title" content="Lessbytes — Perceptual Image Compression for Web & CLI" />
<meta name="twitter:description"
content="Compress images in the browser or CLI with no quality guessing. SSIM-guided binary search finds the smallest file that still looks identical to the original." />
<meta name="twitter:image" content="https://dqev.github.io/lessbytes/assets/og.png" />
<!-- Structured Data: SoftwareApplication -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "SoftwareApplication",
"name": "Lessbytes",
"applicationCategory": "DeveloperApplication",
"operatingSystem": "All",
"description": "Compress images in the browser or CLI with no quality guessing. SSIM-guided binary search finds the smallest file that still looks identical to the original.",
"url": "https://dqev.github.io/lessbytes/",
"image": "https://dqev.github.io/lessbytes/assets/og.png",
"author": {
"@type": "Person",
"name": "Dev Chauhan",
"url": "https://devchauhan.in"
}
}
</script>
<style>
:root {
--heading: #000;
--body: #000;
--body-muted: rgba(0, 0, 0, 0.45);
--background: #fff;
--card-bg: #f7f7f7;
--card-hover-bg: #f1f1f1;
--border: rgba(0, 0, 0, 0.08);
--font-primary: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
--font-code: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", "SFMono-Regular", "Consolas", Menlo, monospace;
--duration-smooth: .15s;
--ease-smooth: cubic-bezier(.19, 1, .22, 1);
--focus-color: rgba(0, 122, 255, 0.5);
--selection-color: #fff;
--selection-bg: #000;
--blue-200: #93c5fd;
--blue-300: #60a5fa;
--text-purple: #a855f7;
--strawberry-200: #fda4af;
--text-warning: #eab308;
--lemon-100: #fef9c3;
--lime-100: #ecfccb;
--blueberry-400: #3b82f6;
--blueberry-300: #6366f1;
--white-100: #ffffff;
}
@media (prefers-color-scheme:dark) {
:root {
--heading: #fff;
--body: #e4e4e7;
--body-muted: rgba(255, 255, 255, 0.5);
--background: #0e0e10;
--card-bg: #181818;
--card-hover-bg: #222225;
--border: rgba(255, 255, 255, 0.08);
--selection-color: #000;
--selection-bg: #fff;
}
}
html.dark {
--heading: #fff;
--body: #e4e4e7;
--body-muted: rgba(255, 255, 255, 0.5);
--background: #0e0e10;
--card-bg: #181818;
--card-hover-bg: #222225;
--border: rgba(255, 255, 255, 0.08);
--selection-color: #000;
--selection-bg: #fff;
}
html.light {
--heading: #000;
--body: #000;
--body-muted: rgba(0, 0, 0, 0.45);
--background: #fff;
--card-bg: #f7f7f7;
--card-hover-bg: #f1f1f1;
--border: rgba(0, 0, 0, 0.08);
--selection-color: #fff;
--selection-bg: #000;
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
border: 0;
outline: 0;
backface-visibility: hidden;
}
::selection {
color: var(--selection-color);
background: var(--selection-bg);
}
:focus-visible {
outline: 2px solid var(--focus-color);
outline-offset: 2px;
}
html,
body {
min-height: 100%;
color: var(--body);
background-color: var(--background);
transition: background-color var(--duration-smooth) var(--ease-smooth),
color var(--duration-smooth) var(--ease-smooth);
}
body {
font-family: var(--font-primary);
font-size: 14px;
font-weight: 400;
line-height: 1.5;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-tap-highlight-color: transparent;
}
a {
color: inherit;
text-decoration: none;
}
p a,
.link-style {
color: inherit;
font-size: inherit;
font-weight: inherit;
line-height: inherit;
transition: all var(--duration-smooth) var(--ease-smooth);
text-underline-offset: 0.25rem;
text-decoration-style: dotted;
text-decoration-thickness: from-font;
text-decoration-color: var(--body-muted);
-webkit-text-decoration-color: var(--body-muted);
text-decoration-line: underline;
display: inline;
}
p a:hover,
.link-style:hover {
text-decoration-style: solid;
text-decoration-color: var(--heading);
-webkit-text-decoration-color: var(--heading);
color: var(--heading);
}
.page-container {
display: flex;
flex-direction: column;
align-items: center;
min-height: 100svh;
padding: 80px 20px 60px;
width: 100%;
}
@media (max-width:600px) {
.page-container {
padding: 60px 15px 40px;
}
}
.content-col {
width: 100%;
max-width: 700px;
display: flex;
flex-direction: column;
}
@media (max-width:768px) {
.content-col {
max-width: 340px;
}
}
@media (max-width:600px) {
.content-col {
max-width: 290px;
}
}
.page-nav {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 6px;
width: 100%;
margin-bottom: 32px;
}
.github-nav-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 2.25rem;
height: 2.25rem;
border-radius: 9999px;
background: var(--border);
color: var(--body-muted);
text-decoration: none;
flex-shrink: 0;
transition: background var(--duration-smooth) var(--ease-smooth),
color var(--duration-smooth) var(--ease-smooth),
transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.github-nav-btn svg {
width: 18px;
height: 18px;
}
.github-nav-btn:hover {
color: var(--heading);
background-color: var(--border);
transform: scale(1.08);
}
.github-nav-btn:active {
transform: scale(0.93);
}
.back-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 2.25rem;
height: 2.25rem;
border-radius: 9999px;
background: var(--border);
color: var(--body-muted);
text-decoration: none;
flex-shrink: 0;
transition: background var(--duration-smooth) var(--ease-smooth),
color var(--duration-smooth) var(--ease-smooth),
transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.back-btn svg {
width: 16px;
height: 16px;
}
.back-btn:hover {
color: var(--heading);
transform: scale(1.08);
}
.back-btn:active {
transform: scale(0.93);
}
.theme-toggle-btn {
background: var(--border);
border: none;
color: var(--body-muted);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
width: 2.25rem;
height: 2.25rem;
border-radius: 9999px;
flex-shrink: 0;
transition: background var(--duration-smooth) var(--ease-smooth),
color var(--duration-smooth) var(--ease-smooth),
transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.theme-toggle-btn svg {
width: 16px;
height: 16px;
transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.theme-toggle-btn:hover {
color: var(--heading);
background-color: var(--border);
transform: scale(1.08);
}
.theme-toggle-btn:active {
transform: scale(0.93);
}
.theme-toggle-btn:active svg {
transform: scale(0.8) rotate(45deg);
}
html.dark .theme-toggle-btn svg {
transform: rotate(-360deg);
}
html.light .theme-toggle-btn svg {
transform: rotate(0deg);
}
.colorLine {
width: 100%;
height: 3px;
background: linear-gradient(92deg,
var(--blue-200) 0%,
var(--blue-300) 14%,
var(--text-purple) 26%,
var(--strawberry-200) 34%,
var(--text-warning) 48%,
var(--lemon-100) 56%,
var(--lemon-100) 72%,
var(--lime-100) 88%,
var(--blueberry-400) 96%,
var(--blueberry-300) 100%);
background-color: var(--white-100);
opacity: 0.7;
transition: opacity var(--duration-smooth) var(--ease-smooth);
}
@media (prefers-color-scheme: dark) {
.colorLine {
opacity: 1;
}
}
html.dark .colorLine {
opacity: 1;
}
html.light .colorLine {
opacity: 0.7;
}
.stickToTop {
position: fixed;
top: 0;
left: 0;
z-index: 9999;
}
.blog-header {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
gap: 12px;
margin-bottom: 32px;
}
.logo-img {
width: 100px;
height: 100px;
border-radius: 0;
object-fit: contain;
}
.logo-img .bg-block {
fill: var(--heading);
transition: fill var(--duration-smooth) var(--ease-smooth);
}
.logo-img .accent-block {
fill: #8b5cf6;
}
.blog-title {
font-size: 26px;
font-weight: 700;
line-height: 1.2;
color: var(--heading);
letter-spacing: -0.01em;
}
.doc-subtitle {
font-size: 15px;
color: var(--body);
font-weight: 500;
max-width: 580px;
line-height: 1.5;
}
.badges-row {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
flex-wrap: wrap;
margin-top: 4px;
}
.badges-row img {
height: 20px;
border-radius: 0;
}
.nav-links {
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
font-size: 14px;
color: var(--body-muted);
margin-top: 4px;
}
.blog-content {
display: flex;
flex-direction: column;
gap: 20px;
font-size: 14px;
line-height: 1.7;
color: var(--body);
}
.blog-content h2 {
font-size: 17px;
font-weight: 600;
color: var(--heading);
line-height: 1.3;
margin-top: 16px;
}
.blog-content h3 {
font-size: 14px;
font-weight: 600;
color: var(--heading);
line-height: 1.3;
margin-top: 8px;
}
.blog-content p {
margin: 0;
}
.blog-content ul,
.blog-content ol {
padding-left: 20px;
display: flex;
flex-direction: column;
gap: 6px;
}
.blog-content li {
line-height: 1.6;
}
.blog-content strong {
font-weight: 600;
color: var(--heading);
}
.blog-content blockquote {
border-left: 2px solid var(--border);
padding-left: 16px;
color: var(--body-muted);
font-style: italic;
}
.blog-content code {
font-family: var(--font-code);
font-size: 13px;
background: var(--card-bg);
padding: 1px 5px;
border-radius: 4px;
color: var(--heading);
}
.blog-content pre {
background: var(--card-bg);
border-radius: 10px;
padding: 16px 18px;
overflow: hidden;
font-family: var(--font-code);
font-size: 13px;
line-height: 1.6;
color: var(--heading);
scrollbar-width: none;
-ms-overflow-style: none;
}
.blog-content pre::-webkit-scrollbar {
display: none;
width: 0;
height: 0;
}
.blog-content .pre-wrap {
position: relative;
}
.blog-content pre .code-wrap {
overflow-x: auto;
scrollbar-width: none;
-ms-overflow-style: none;
}
.blog-content pre .code-wrap::-webkit-scrollbar {
display: none;
width: 0;
height: 0;
}
.blog-content pre code {
background: none;
padding: 0;
border-radius: 0;
font-size: inherit;
}
.copy-btn {
position: absolute;
top: 8px;
right: 8px;
height: 28px;
border-radius: 6px;
border: none;
background: var(--card-bg);
color: var(--body-muted);
cursor: pointer;
display: flex;
align-items: center;
gap: 4px;
padding: 0 7px;
font-family: var(--font-primary);
font-size: 11px;
font-weight: 500;
transition: background var(--duration-smooth) var(--ease-smooth),
color var(--duration-smooth) var(--ease-smooth);
}
.copy-btn:hover {
background: var(--card-hover-bg);
color: var(--heading);
}
.copy-btn svg {
width: 14px;
height: 14px;
flex-shrink: 0;
}
.copy-btn .ci {
display: flex;
align-items: center;
gap: 3px;
animation: ci-in 0.2s cubic-bezier(.19,1,.22,1) both;
}
@keyframes ci-in {
from { opacity: 0; transform: scale(0.85); }
to { opacity: 1; transform: scale(1); }
}
.blog-content hr {
border: none;
height: 1px;
background: var(--border);
margin: 12px 0;
}
.blog-content img {
max-width: 100%;
border-radius: 12px;
border: 0;
object-fit: cover;
}
.doc-table {
width: 100%;
border-collapse: collapse;
font-size: 13px;
margin: 8px 0;
}
.doc-table th,
.doc-table td {
padding: 8px 10px;
text-align: left;
border-bottom: 1px solid var(--border);
}
.doc-table th {
font-weight: 600;
color: var(--heading);
}
.blog-footer {
margin-top: 40px;
padding-top: 24px;
border-top: 1px solid var(--border);
display: flex;
align-items: center;
justify-content: space-between;
}
</style>
</head>
<body>
<div class="colorLine stickToTop"></div>
<main class="page-container">
<div class="content-col">
<div class="page-nav">
<a href="https://github.com/dqev/lessbytes" target="_blank" rel="noopener noreferrer" class="github-nav-btn" aria-label="GitHub Repository" title="GitHub Repository">
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" width="16" height="16">
<path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"/>
</svg>
</a>
<button class="theme-toggle-btn" id="theme-toggle" aria-label="Toggle Theme">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" height="16" width="16">
<path fill="currentColor"
d="M7.30566 3.67212c0.63864 -0.29382 1.31159 -0.17926 1.81055 0.15234 0.51302 0.34113 0.86535 0.91807 0.92679 1.56934 0.446 4.7344 4.3291 8.6166 9.0634 9.0625 0.6513 0.0614 1.2273 0.4147 1.5684 0.9277 0.3537 0.5322 0.46 1.2612 0.0879 1.9366 -1.7007 3.085 -4.9864 5.1787 -8.7627 5.1787 -5.52285 0 -10 -4.4772 -10 -10 0.00027 -3.77605 2.09383 -7.06219 5.17871 -8.76273z"
stroke-width="1" />
</svg>
</button>
</div>
<article>
<header class="blog-header">
<a href="https://dqev.github.io/lessbytes/" aria-label="Lessbytes Homepage">
<svg class="logo-img" viewBox="0 0 100 100" width="100" height="100" xmlns="http://www.w3.org/2000/svg">
<rect class="bg-block" x="6" y="6" width="18" height="18" rx="2.5"/>
<rect class="bg-block" x="28" y="6" width="18" height="18" rx="2.5"/>
<rect class="bg-block" x="50" y="6" width="18" height="18" rx="2.5"/>
<rect class="bg-block" x="72" y="6" width="18" height="18" rx="2.5"/>
<rect class="bg-block" x="28" y="28" width="18" height="18" rx="2.5" opacity="0.75"/>
<rect class="bg-block" x="50" y="28" width="18" height="18" rx="2.5" opacity="0.75"/>
<rect class="accent-block" x="72" y="28" width="18" height="18" rx="2.5" opacity="0.75"/>
<rect class="accent-block" x="50" y="50" width="18" height="18" rx="2.5" opacity="0.5"/>
<rect class="accent-block" x="72" y="50" width="18" height="18" rx="2.5" opacity="0.5"/>
<rect class="accent-block" x="72" y="72" width="18" height="18" rx="2.5" opacity="0.28"/>
</svg>
</a>
<h1 class="blog-title">Lessbytes</h1>
<p class="doc-subtitle">
<strong>A tool for compressing images. It picks the quality level for you and keeps the smallest format that still looks fine.</strong>
</p>
<div class="badges-row">
<img alt="npm version" src="https://img.shields.io/npm/v/lessbytes?style=flat-square&color=6C5CE7&label=npm">
<img alt="bundle size" src="https://img.shields.io/badge/browser%20bundle-15%20KB%20min-00B894?style=flat-square">
<img alt="zero browser deps" src="https://img.shields.io/badge/browser%20deps-0-00B894?style=flat-square">
<img alt="types" src="https://img.shields.io/badge/types-included-3178C6?style=flat-square&logo=typescript&logoColor=white">
</div>
</header>
<div class="blog-content">
<p>Available as a CLI tool and a JS library (browser + Node).</p>
<h2>What it does</h2>
<ul>
<li>Compresses JPEG, PNG, WebP, and AVIF images</li>
<li>Automatically picks a quality level, instead of you setting a fixed number</li>
<li>Can try multiple output formats and keep whichever is smallest</li>
<li>Can process a whole folder of images at once</li>
<li>If compressing doesn't actually save space, it keeps the original file</li>
</ul>
<h2>Install</h2>
<pre><code>npm install lessbytes</code></pre>
<p>Browser, no build step:</p>
<pre><code><script src="https://unpkg.com/lessbytes"></script>
<script>
lessbytes.compress(file).then(r => console.log(`${(r.ratio * 100).toFixed(1)}% smaller`));
</script></code></pre>
<hr />
<h2 id="api">API</h2>
<pre><code>// ESM / bundlers
import { compress, compressBatch, isFormatSupported } from 'lessbytes';
// CommonJS
const { compress } = require('lessbytes');
// Browser <script> tag — exposes a global `lessbytes`</code></pre>
<h3><code>compress(input, options?)</code></h3>
<p><code>input</code> can be a <code>File</code>, <code>Blob</code>, <code>HTMLImageElement</code>, or a URL string.</p>
<pre><code>const result = await compress(file, {
format: 'webp', // 'webp' | 'auto' | 'jpeg' | 'png' | 'avif'
maxWidth: 1920, // resizes down if larger, never upscales
maxHeight: null,
targetSize: 100 * 1024, // optional byte limit, e.g. for upload restrictions
background: '#ffffff', // fill color used if flattening transparency
keepSmallest: true // return original if compression makes it bigger
});
result.blob // compressed image
result.format // e.g. 'webp'
result.ratio // e.g. 0.84 (file is 84% smaller)
result.toFile('name.webp') // wraps result.blob as a File</code></pre>
<p>Example, upload handler:</p>
<pre><code>input.addEventListener('change', async () => {
const { blob, toFile } = await compress(input.files[0], { maxWidth: 1920 });
preview.src = URL.createObjectURL(blob);
formData.append('photo', toFile('photo.webp'));
});</code></pre>
<h3><code>compressBatch(inputs, options?)</code></h3>
<p>Compress multiple files, with a progress callback.</p>
<pre><code>const results = await compressBatch(files, {
concurrency: 3,
maxWidth: 1600,
onProgress: (done, total, last) => {
console.log(`${done}/${total} done`);
}
});</code></pre>
<h3><code>isFormatSupported(mime)</code></h3>
<p>Returns <code>true</code>/<code>false</code> for whether the current browser can encode that format (mainly useful for checking AVIF support before showing it as an option).</p>
<hr />
<h2 id="cli">CLI</h2>
<img src="assets/terminal.png" alt="Lessbytes CLI Terminal Interface" width="100%" />
<pre><code>npm install -g lessbytes
lessbytes <files...|dir> [options]</code></pre>
<p>Requires <a href="https://sharp.pixelplumbing.com" target="_blank" rel="noopener noreferrer">sharp</a>. If it's missing, the CLI prints the install command needed.</p>
<blockquote>
<p>Note: <code>npx lessbytes</code> is not supported — install it globally first.</p>
</blockquote>
<h3>Basic usage</h3>
<pre><code>lessbytes photo.jpg # writes photo.min.webp next to it
lessbytes *.png -o out/ # compress a batch into a folder
lessbytes ./assets -r -o build/img # compress a folder, including subfolders</code></pre>
<h3>More examples</h3>
<pre><code>lessbytes hero.png --format webp --quality 80 # fixed quality, no auto-search
lessbytes banner.jpg --max-size 100kb # keep file under a size limit
lessbytes huge.jpg --max-width 1920 # resize down, keep aspect ratio
lessbytes icon.png --keep-larger # save even if result is bigger</code></pre>
<h3>Interactive mode</h3>
<p>Run with no arguments for a guided prompt:</p>
<pre><code>lessbytes</code></pre>
<pre><code> Image file or folder › photo.jpg
Output format
1 Auto (default)
2 WebP
3 AVIF
4 JPEG
5 PNG
› 1
Compression mode
1 Smart — auto quality (default)
2 Target file size
3 Fixed quality
› 1
Max width in px (blank = no limit) › 1920
Output path (blank = beside source) › build/img</code></pre>
<h3>Flags</h3>
<table class="doc-table">
<thead>
<tr>
<th>Flag</th>
<th>Description</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-o, --output <path></code></td>
<td>Output file or folder</td>
<td>next to source, <code>*.min.*</code></td>
</tr>
<tr>
<td><code>-f, --format <fmt></code></td>
<td><code>auto</code>, <code>jpeg</code>, <code>webp</code>, <code>png</code>, <code>avif</code></td>
<td><code>webp</code></td>
</tr>
<tr>
<td><code>-q, --quality <1-100></code></td>
<td>Fixed quality, skips auto mode</td>
<td>—</td>
</tr>
<tr>
<td><code>--max-size <size></code></td>
<td>Size limit, e.g. <code>100kb</code>, <code>1.5mb</code></td>
<td>—</td>
</tr>
<tr>
<td><code>--max-width <px></code></td>
<td>Max width, keeps aspect ratio</td>
<td>—</td>
</tr>
<tr>
<td><code>--max-height <px></code></td>
<td>Max height, keeps aspect ratio</td>
<td>—</td>
</tr>
<tr>
<td><code>-r, --recursive</code></td>
<td>Include subfolders</td>
<td>off</td>
</tr>
<tr>
<td><code>--suffix <str></code></td>
<td>Suffix for output filename</td>
<td><code>.min</code></td>
</tr>
<tr>
<td><code>--keep-larger</code></td>
<td>Save even if the result is bigger</td>
<td>off</td>
</tr>
<tr>
<td><code>--dry-run</code></td>
<td>Simulate compression without writing files</td>
<td>off</td>
</tr>
<tr>
<td><code>-w, --watch</code></td>
<td>Watch input directory for new assets</td>
<td>off</td>
</tr>
<tr>
<td><code>-s, --silent</code></td>
<td>Only print errors</td>
<td>off</td>
</tr>
<tr>
<td><code>-i, --interactive</code></td>
<td>Force interactive prompt</td>
<td>off</td>
</tr>
<tr>
<td><code>--logo</code></td>
<td>Print logo and exit</td>
<td>—</td>
</tr>
<tr>
<td><code>-h, --help</code></td>
<td>Show help</td>
<td>—</td>
</tr>
<tr>
<td><code>-v, --version</code></td>
<td>Show version</td>
<td>—</td>
</tr>
</tbody>
</table>
<h3>Format notes</h3>
<ul>
<li><code>webp</code> (default): converts everything to WebP.</li>
<li><code>auto</code>: tries several formats per image, keeps the smallest. Skips AVIF if unsupported.</li>
<li>Any other format: only that one is used. JPEG flattens transparency onto a background color (white by default).</li>
</ul>
<h3><code>--max-size</code> behavior</h3>
<p>It first adjusts quality to try to hit the limit. If that's not enough, it also shrinks the image dimensions and tries again. If the target still can't be reached, it saves the smallest version possible and marks it <code>⚠ over target</code>.</p>
<h3>Output example</h3>
<pre><code>lessbytes v1.2.3 compressing 1 image
✓ photo.jpg 235.8 KB → 36.9 KB -84% webp q93
Done. 235.8 KB → 36.9 KB (84.4% smaller)</code></pre>
<p>If resized, it shows the scale (e.g. <code>60% scale</code>). If compression didn't help, it shows <code>kept original</code>.</p>
<h3>Exit codes</h3>
<table class="doc-table">
<thead>
<tr>
<th>Code</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>0</code></td>
<td>Ran successfully</td>
</tr>
<tr>
<td><code>1</code></td>
<td>Bad input, no images found, <code>sharp</code> missing, or everything failed</td>
</tr>
</tbody>
</table>
<p>Partial failures (some images succeed, some don't) still exit <code>0</code> — check individual rows for errors.</p>
<hr />
<h2>Compatibility</h2>
<ul>
<li><strong>Node:</strong> 16+ for the CLI</li>
<li><strong>Browser:</strong> works anywhere Canvas is supported; AVIF is used if available, otherwise falls back to WebP or JPEG</li>
<li><strong>Bundlers:</strong> ships ESM, CommonJS, and UMD — works with Vite, webpack, Rollup, esbuild, or a plain <code><script></code> tag</li>
</ul>
</div>
<footer class="blog-footer">
<span style="font-size: 13px; color: var(--body-muted);"><a href="https://github.com/dqev/lessbytes/blob/main/LICENSE" class="link-style" target="_blank" rel="noopener noreferrer">MIT License</a> © 2026 <a href="https://devchauhan.in" class="link-style" target="_blank" rel="noopener noreferrer">Dev Chauhan</a></span>
<a href="https://github.com/dqev/lessbytes" class="link-style" target="_blank" rel="noopener noreferrer">GitHub →</a>
</footer>
</article>
</div>
</main>
<script>
const themeToggleBtn = document.getElementById('theme-toggle');
function getSystemTheme() {
return window.matchMedia('(prefers-color-scheme:dark)').matches ? 'dark' : 'light';
}
function getActiveTheme() {
return localStorage.getItem('theme') || getSystemTheme();
}
function applyTheme(t) {
document.documentElement.className = t;
}
applyTheme(getActiveTheme());
window.addEventListener('storage', function (e) {