88
99데모를 통하여 이미지 url, 이미지 첨부파일을 리사이즈하는 모습을 볼 수 확인할 수 있다.
1010
11- https://kode-team.github.io/image-resize/
11+ > https://kode-team.github.io/image-resize/
1212
1313
1414## Installation
@@ -18,180 +18,90 @@ https://kode-team.github.io/image-resize/
1818```
1919npm install image-resize
2020yarn add image-resize
21+ bun add -d image-resize
2122```
2223
2324
2425## Usage
2526
26- 먼저 ` ImageResize ` 객체를 만들어서 ` play() ` 메서드를 실행하는 방식이다 .
27+ ` import ` 로 함수를 불러서 비동기 방식으로 사용하면 된다 .
2728
2829### Module environment
2930
3031``` javascript
31- import ImageResize from ' image-resize' ;
32+ import imageResize from ' image-resize'
3233
33- var imageResize = new ImageResize ( {
34+ let res = await imageResize ( ' image.jpg ' , {
3435 format: ' png' ,
35- width: 640
36- });
37- imageResize .play (' image.jpg' );
36+ width: 640 ,
37+ })
3838```
3939
4040### Vanilla environment
4141
4242``` html
43- <script src =" ./ImageResize .umd.js" ></script >
43+ <script src =" imageResize .umd.js" ></script >
4444
4545<script >
46- var imageResize = new ImageResize ({
47- format: ' png' ,
48- width: 640
49- });
50- imageResize .play (' image.jpg' );
46+ let res = await imageResize (' image.jpg' , {
47+ format: ' png' ,
48+ width: 640 ,
49+ })
5150 </script >
5251```
5352
5453
55- ## Options
56-
57- ` image-resize ` 에서 다음과 같은 옵션을 사용하여 컨트롤할 수 있다.
58-
59- ### Basic
60-
61- | Name | Type | Default | Description |
62- | :----------:| :------:| :---------:| :--------------------------------------------------------|
63- | quality | number | ` .75 ` | jpg 이미지일때의 이미지 퀄리티값 |
64- | format | string | ` jpg ` | 출력할 포맷. ` png,jpg,webp ` |
65- | outputType | string | ` base64 ` | 출력방식. ` base64,canvas,blob ` |
66- | width | number | ` 320 ` | 조절할 가로사이즈 |
67- | height | number | ` null ` | 조절할 세로 사이즈. 한쪽값이 있는쪽으로 기준이 되어 조절한다. |
68- | reSample | number | ` 2 ` | 리새플링 횟수. 수치가 높을수록 경계선이 부드러워지지만 처리속도는 느려진다. 최대 4까지 적용된다. |
69- | bgColor | string | ` #ffffff ` | 캔버스 배경색 |
70- | sharpen | number | ` 0.75 ` | 선명하게 강도 |
71-
72-
73- ## Methods
74-
75- 만들어진 인스턴스 객체에서 액션을 실행하는 메서드가 제공된다. 메서드를 사용하기 위하여 다음과 같이 인스턴스 객체를 만들었다.
76-
77- ``` javascript
78- var imageResize = new ImageResize ();
79- ```
80-
81- 좀더 자세하게 사용하는 방법에 대해서는 데모 소스를 참고.
82- https://github.com/kode-team/image-resize/blob/main/src/demo/index.js
54+ ## Source
8355
56+ 사용하기 먼저 어떤 형식의 이미지 데이터를 지원하는지 확인해볼 필요가 있다.
57+ 지원하는 이미지 데이터의 형식은 다음과 같다.
8458
85- ### play
86-
87- 실질적으로 리사이즈를 실행한다.
88-
89- - Param ` String,HTMLInputElement,File,Blob `
90- - Return ` string,object,HTMLCanvasElement `
91-
92- ``` javascript
93- // image url
94- try {
95- let res = await imageResize .play (' image.jpg' )
96- console .log (res);
97- } catch (e) {
98- console .error (e);
99- }
100-
101- // <input type="file" id="upload"/>
102- let res = await imageResize .play (document .getElementById (' upload' ));
103-
104- // File
105- let res = await imageResize .play (element .files [0 ]);
106-
107- // Blob
108- let res = await imageResize .play (new Blob (src, { type: ' image/jpeg' }));
109- ```
110-
111- ### updateOptions
112-
113- 정의되어있는 객체의 옵션을 변경한다.
114-
115- - Param ` Object `
116- - Return ` ImageResize `
117-
118- ``` javascript
119- imageResize .updateOptions ({
120- width: 800 ,
121- format: ' jpg' ,
122- quality: .5
123- });
124- ```
59+ - ` String ` : 이미지 url
60+ - ` File ` : File 형식의 객체
61+ - ` Blob ` : Blob 타입의 객체
62+ - ` HTMLCanvasElement ` : canvas 엘리먼트
12563
126- 다음과 같이 다른 메서드와 같이 묶어서 사용할 수 있다.
12764
128- ``` javascript
129- imageResize
130- .updateOptions ({ width: 400 })
131- .play (' image.jpg' )
132- .then ();
133-
134- let res = await imageResize
135- .updateOptions ({ width: 400 })
136- .play (' image.jpg' );
137- ```
138-
139- ### get
140-
141- 이미지나 파일첨부폼을 이용해서 캔버스로 가져온다.
142-
143- - Param ` string,HTMLInputElement,File,Blob `
144- - Return ` HTMLCanvasElement `
145-
146- ``` javascript
147- // image url
148- imageResize .get (' image.jpg' ).then ();
149-
150- // <input type="file" id="upload"/>
151- let res = await imageResize .get (document .getElementById (' upload' ));
152- ```
65+ ## Options
15366
154- ### resize
67+ 다음과 같은 옵션을 사용할 수 있다.
15568
156- 리사이즈 실행하는 역할을 한다.
69+ | Name | Type | Default | Description |
70+ | :----------:| :------:| :-------------:| :--------------------------------------------------------|
71+ | width | number | ` 320 ` | 조절할 가로사이즈 |
72+ | height | number | ` undefined ` | 조절할 세로 사이즈. 한쪽값이 있는쪽으로 기준이 되어 조절한다. |
73+ | format | string | ` jpg ` | 출력할 포맷. ` png,jpg,webp ` |
74+ | outputType | string | ` base64 ` | 출력방식. ` base64,canvas,blob ` |
75+ | quality | number | ` .75 ` | jpg 이미지일때의 이미지 퀄리티값 |
76+ | reSample | number | ` 2 ` | 리샘플링 횟수. 수치가 높을수록 경계선이 부드러워지지만 처리속도는 느려진다. 최대 4까지 적용된다. |
77+ | sharpen | number | ` 0.75 ` | 선명함의 강도 |
78+ | bgColor | string | ` transparent ` | 캔버스 배경색 (배경이 투명한 이미지를 사용하면 영향을 받을 수 있다.) |
15779
158- - Param ` HTMLCanvasElement `
159- - Return ` HTMLCanvasElement `
80+ ### 사이즈 값 조정
16081
161- ``` javascript
162- imageResize .resize (document .getElementById (' canvas' )).then ();
163- ```
82+ width, height 사이즈 값은 다음과 같은 조건을 따른다.
16483
165- ### output
84+ - width, height 둘다 있을때: width 값이 기준이 된다.
85+ - width 값이 없을때: height 값이 기준이 된다.
86+ - height 값이 없을때: width 값이 기준이 된다.
87+ - width, height 둘다 없을때: width 값이 기준이 된다.
16688
167- 결과물을 출력하는 역할을 한다 .
89+ 만약 height 값을 기준으로 사용하고 싶다면 ` width ` 값을 ` 0 ` 이나 ` undefined ` 으로 넣어줘야한다 .
16890
169- - Param ` HTMLCanvasElement `
170- - Return ` string,object,HTMLCanvasElement `
91+ ### 배경색
17192
172- ``` javascript
173- imageResize .output (document .getElementById (' canvas' )).then ();
174- ```
93+ 기본값으로 ` transparent ` 로 설정되어있다.
94+ 투명한 배경 이미지에 배경색을 넣고싶다면 ` #ffffff ` 같은 값으로 넣어주면 배경색이 들어가게 된다.
17595
17696
177- ## Mix methods
97+ ## Output
17898
179- 메서드들이 ` Promise ` 로 리턴되기 때문에 다음과 같이 연결해서 사용할 수 있다.
180- 체인 형식이다보니 중간에 다른 함수를 끼워넣어서 사용할 수 있다 .
99+ 함수를 실행하고 반환해주는 데이터의 형식이다.
100+ 옵션에서 ` outputType ` 값에 맞는 형식으로 데이터가 리턴된다 .
181101
182- ``` javascript
183- try {
184- const imageResize = new ImageResize ();
185- let res = await imageResize .updateOptions ({ width: 640 }).get (' image.jpg' );
186- res = await imageResize .resize (res);
187- res = imageResize .sharpen (res);
188- res = await ready (res);
189- res = await imageResize .output (res);
190- console .log (res);
191- } catch (e) {
192- console .error (error);
193- }
194- ```
102+ - ` base64 ` : base64 형식의 문자
103+ - ` blob ` : Blob 타입의 객체
104+ - ` canvas ` : canvas 엘리먼트
195105
196106
197107## Development
@@ -201,24 +111,11 @@ try {
201111
202112```
203113// development
204- yarn run dev
114+ npm run dev
205115
206116// production
207- yarn run build
117+ npm run build
208118
209119// preview
210- yarn run start
120+ npm run preview
211121```
212-
213-
214- ## Support
215-
216- ### browser
217-
218- - Google chrome
219- - Safari (문제가 생길 수 있습니다.)
220-
221- ### node.js
222-
223- 이 모듈은 브라우저에서 이미지를 리사이즈 하기위하여 만들어졌다.
224- node.js 환경에서는 [ sharp] ( https://github.com/lovell/sharp ) 같은 모듈들을 사용을 권장드립니다.
0 commit comments