File tree Expand file tree Collapse file tree 4 files changed +87
-9
lines changed Expand file tree Collapse file tree 4 files changed +87
-9
lines changed Original file line number Diff line number Diff line change
1
+ name : Build
2
+
3
+ run-name : Build Code
4
+
5
+ on :
6
+ push :
7
+ branches : ['main']
8
+
9
+ permissions :
10
+ contents : write
11
+
12
+ concurrency :
13
+ group : " build"
14
+ cancel-in-progress : true
15
+
16
+ jobs :
17
+ build :
18
+ runs-on : ubuntu-latest
19
+
20
+ steps :
21
+ - name : Checkout Repo
22
+ uses : actions/checkout@v3
23
+
24
+ - name : Build
25
+ run : |
26
+ npm ci
27
+ npm run build
28
+ cd dist
29
+ touch .nojekyll
30
+
31
+ - name : Minify Code
32
+ uses : Lenni009/minify-js@main
33
+ with :
34
+ directory : dist
35
+ overwrite : true
36
+
37
+ - name : Deploy to GitHub Pages
38
+ uses : JamesIves/github-pages-deploy-action@v4
39
+ with :
40
+ folder : dist # The folder the action should deploy.
Original file line number Diff line number Diff line change
1
+ name : Test Build
2
+ run-name : Test Build
3
+
4
+ on :
5
+ pull_request :
6
+ types : [opened, synchronize]
7
+
8
+ concurrency :
9
+ group : " testbuild"
10
+ cancel-in-progress : true
11
+
12
+ jobs :
13
+ Build :
14
+ runs-on : ubuntu-latest
15
+
16
+ permissions :
17
+ pull-requests : write
18
+ contents : write
19
+
20
+ steps :
21
+ - name : Checkout Repo
22
+ uses : actions/checkout@v3
23
+
24
+ - name : Test Build
25
+ uses : Lenni009/test-build-vite-action@main
Original file line number Diff line number Diff line change 4
4
< head >
5
5
< meta charset ="UTF-8 ">
6
6
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7
- < title > Document </ title >
7
+ < title > Image Compressor </ title >
8
8
< script type ="module " src ="src/main.ts "> </ script >
9
+ < style >
10
+ h1 {
11
+ text-align : center;
12
+ }
13
+
14
+ .container {
15
+ margin-block-start : 1rem ;
16
+ }
17
+ </ style >
9
18
</ head >
10
19
11
20
< body >
12
- < h1 > Image Compressor</ h1 >
13
- < h2 > Input</ h2 >
14
- < input type ="file ">
21
+ < div class ="container ">
22
+ < h1 > Image Compressor</ h1 >
23
+ < p > Compresses Images to below 10MB</ p >
24
+ < h2 > Input</ h2 >
25
+ < input type ="file ">
15
26
16
- < h2 > Output</ h2 >
17
- < a href ="" id ="download " download style ="display: none; "> Download</ a >
18
- < p id ="status " style ="display: none; "> Compressing...</ p >
27
+ < h2 > Output</ h2 >
28
+ < a href ="" id ="download " download style ="display: none; "> Download</ a >
29
+ < p id ="status " style ="display: none; "> Compressing...</ p >
30
+ </ div >
19
31
</ body >
20
32
21
33
</ html >
Original file line number Diff line number Diff line change
1
+ import '@picocss/pico' ;
1
2
import { compress , EImageType } from 'image-conversion' ;
2
3
3
4
const input = document . querySelector ( 'input' ) ;
@@ -30,10 +31,10 @@ async function compressFile(file: File): Promise<Blob> {
30
31
if ( file . size < maxSize ) return file ; // if below 10 MB, don't do anything
31
32
const name = file . name ;
32
33
const res = await compress ( file , {
33
- quality, //The compressed image size is 9000kb
34
+ quality,
34
35
type : EImageType . JPEG ,
35
36
scale : 1 ,
36
- } ) ; // NoSonar compress to 9MB
37
+ } ) ;
37
38
quality -= 0.01 ; // NoSonar reduce quality by 1%;
38
39
if ( res . size > maxSize ) return await compressFile ( new File ( [ res ] , name , { type : 'image/jpeg' } ) ) ;
39
40
quality = 1 ; // reset quality
You can’t perform that action at this time.
0 commit comments