@2080code/pic-processer 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +16 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -7,11 +7,15 @@
7
7
  ## 介绍
8
8
  用来对图片做压缩,把 File 对象转为 dataURL,又或者把 dataURL 转为 File 对象。
9
9
 
10
+ ---
11
+
10
12
  ## 安装
11
13
  ```bash
12
14
  npm install @2080code/pic-processer
13
15
  ```
14
16
 
17
+ ---
18
+
15
19
  ## 使用
16
20
  ```javascript
17
21
  import PicProcesser from '@2080code/pic-processer'
@@ -31,6 +35,8 @@ picProcesser.compress(file, 0.2)
31
35
  picProcesser.getDataURL(file)
32
36
  ```
33
37
 
38
+ ---
39
+
34
40
  ## 方法
35
41
  ### compress
36
42
  压缩图片质量、改变图片尺寸,输出 dataURL
@@ -38,7 +44,7 @@ picProcesser.getDataURL(file)
38
44
  ```javascript
39
45
  picProcesser.compress(file, 0.2, 1000, 'image/png')
40
46
  ```
41
- #### 参数
47
+ ##### 参数
42
48
  参数|类型|默认值|说明
43
49
  ---|---|---|---
44
50
  `file` | File | `null` | 图片文件
@@ -46,29 +52,33 @@ picProcesser.compress(file, 0.2, 1000, 'image/png')
46
52
  `maxWidth` | number | `null` | 图片宽度上限,>1的整数,单位px,`0` 或 `null` 表示不限制,输出图片的高度会等比例缩放
47
53
  `mime` | string | `image/jpeg` | 输出图片类型
48
54
 
49
- #### 返回
55
+ ##### 返回
50
56
  返回值|类型|说明
51
57
  ---|---|---
52
58
  `Promise<string>` | `Promise<string>` | 压缩后的图片 dataURL 编码
53
59
 
54
60
  *注意:因为是借助 canvas 渲染输出,几乎是重绘了图片,所以如果压缩比率(`ratio`)设置得太高,最终文件字节可能会比原图更大*
55
61
 
62
+ ---
63
+
56
64
  ### getDataURL
57
65
  File 转 dataURL
58
66
 
59
67
  ```javascript
60
68
  picProcesser.getDataURL(file)
61
69
  ```
62
- #### 参数
70
+ ##### 参数
63
71
  参数|类型|默认值|说明
64
72
  ---|---|---|---
65
73
  `file` | File|Blob | `null` | 图片文件
66
74
 
67
- #### 返回
75
+ ##### 返回
68
76
  返回值|类型|说明
69
77
  ---|---|---
70
78
  `Promise<FileReader>` | `Promise<FileReader>` | 完整的 FileReader 对象,通过`result`属性获取 base64 编码
71
79
 
80
+ ---
81
+
72
82
  ### dataURLtoFile
73
83
  dataURL 转 File 对象
74
84
 
@@ -76,13 +86,13 @@ dataURL 转 File 对象
76
86
  picProcesser.dataURLtoFile('export.jpg', dataURL)
77
87
  ```
78
88
 
79
- #### 参数
89
+ ##### 参数
80
90
  参数|类型|默认值|说明
81
91
  ---|---|---|---
82
92
  `fileName` | string | `null` | 输出文件名
83
93
  `dataURL` | string | `null` | base64编码
84
94
 
85
- #### 返回
95
+ ##### 返回
86
96
  返回值|类型|说明
87
97
  ---|---|---
88
98
  `Promise<File>` | `Promise<File>` | File 对象
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2080code/pic-processer",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "图片压缩、改变图片尺寸、File 和 dataURL 互转",
5
5
  "main": "index.js",
6
6
  "types": "./src/types.ts",