@leafer/image 1.0.0-beta.2 → 1.0.0-beta.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/image",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "@leafer/image",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,6 +19,6 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "devDependencies": {
22
- "@leafer/interface": "1.0.0-beta.2"
22
+ "@leafer/interface": "1.0.0-beta.4"
23
23
  }
24
24
  }
@@ -0,0 +1,47 @@
1
+ import { ILeaferImage, ILeaferImageConfig, IFunction, IObject } from '@leafer/interface'
2
+ import { Platform } from '@leafer/platform'
3
+
4
+
5
+ export class LeaferImageBase implements ILeaferImage {
6
+
7
+ public view: any
8
+
9
+ public width: number
10
+ public height: number
11
+
12
+ public ready: boolean
13
+
14
+ public options: ILeaferImageConfig
15
+
16
+ constructor(_options: ILeaferImageConfig) {
17
+ this.options = _options
18
+ }
19
+
20
+ public load(onSuccess: IFunction, onError: IFunction): void {
21
+ Platform.origin.loadImage(this.options.url).then((img) => {
22
+ this.ready = true
23
+ this.width = img.naturalWidth || img.width
24
+ this.height = img.naturalHeight || img.height
25
+ this.view = img
26
+ if (onSuccess) onSuccess(this)
27
+ }).catch((e) => {
28
+ if (onError) onError(e)
29
+ })
30
+ }
31
+
32
+ public getCanvas(width: number, height: number, opacity?: number, _filters?: IObject): any {
33
+ width || (width = this.width)
34
+ height || (height = this.height)
35
+ const canvas = Platform.origin.createCanvas(width, height)
36
+ const ctx = canvas.getContext('2d')
37
+ if (opacity) ctx.globalAlpha = opacity
38
+ ctx.drawImage(this.view, 0, 0, width, height)
39
+ return canvas
40
+ }
41
+
42
+ public destory(): void {
43
+ this.view = null
44
+ this.options = null
45
+ }
46
+
47
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { ImageManager } from './ImageManager'
2
-
1
+ export { LeaferImageBase } from './LeaferImageBase'
2
+ export { ImageManager } from './ImageManager'