@intuiface/capacitor-plugin-screenshot 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -59,10 +59,11 @@ Function to take a screenshot
59
59
 
60
60
  #### ScreenshotOptions
61
61
 
62
- | Prop | Type | Description |
63
- | ------------- | ------------------- | ------------------------------------------- |
64
- | **`quality`** | <code>number</code> | The quality of the screenshot between 0-100 |
65
- | **`name`** | <code>string</code> | The name of the file to save |
62
+ | Prop | Type | Description |
63
+ | ------------- | ------------------- | ----------------------------------------------- |
64
+ | **`size`** | <code>number</code> | The desired size (here width) of the screenshot |
65
+ | **`quality`** | <code>number</code> | The quality of the screenshot between 0-100 |
66
+ | **`name`** | <code>string</code> | The name of the file to save |
66
67
 
67
68
  </docgen-api>
68
69
 
@@ -194,8 +194,9 @@ public class CapacitorScreenshotPlugin extends Plugin {
194
194
  // generate the final bitmap at the right size from the bitmap created
195
195
  bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height);
196
196
 
197
+ int desiredWidth = savedCall.getInt("size", width);
197
198
  // scale but keep ratio
198
- int scaledWidth = Math.min(width, 1920);
199
+ int scaledWidth = Math.min(width, desiredWidth);
199
200
  int scaledHeight = height * scaledWidth / width;
200
201
  bitmap = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, false);
201
202
 
package/dist/docs.json CHANGED
@@ -67,6 +67,13 @@
67
67
  "tags": [],
68
68
  "methods": [],
69
69
  "properties": [
70
+ {
71
+ "name": "size",
72
+ "tags": [],
73
+ "docs": "The desired size (here width) of the screenshot",
74
+ "complexTypes": [],
75
+ "type": "number"
76
+ },
70
77
  {
71
78
  "name": "quality",
72
79
  "tags": [],
@@ -7,6 +7,10 @@ export interface CapacitorScreenshotPlugin {
7
7
  getScreenshot(options: ScreenshotOptions): Promise<ScreenshotValue | null>;
8
8
  }
9
9
  export interface ScreenshotOptions {
10
+ /**
11
+ * The desired size (here width) of the screenshot
12
+ */
13
+ size: number;
10
14
  /**
11
15
  * The quality of the screenshot between 0-100
12
16
  */
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CapacitorScreenshotPlugin {\n /**\n * Function to take a screenshot\n * @param {ScreenshotOptions} options : options with quality desired for the screenshot\n * @returns {Promise<ScreenshotValue | null>} Promise with the base64 string of the image if available, null instead\n */\n getScreenshot(options: ScreenshotOptions): Promise<ScreenshotValue | null>;\n}\n\nexport interface ScreenshotOptions {\n /**\n * The quality of the screenshot between 0-100\n */\n quality: number;\n /**\n * The name of the file to save\n */\n name?: string;\n}\n\nexport interface ScreenshotValue {\n /**\n * The base64 string of the screenshot.\n * Can be null\n */\n base64?: string;\n /**\n * The file uri where the image is saved\n * Can be null\n */\n URI?: string;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CapacitorScreenshotPlugin {\n /**\n * Function to take a screenshot\n * @param {ScreenshotOptions} options : options with quality desired for the screenshot\n * @returns {Promise<ScreenshotValue | null>} Promise with the base64 string of the image if available, null instead\n */\n getScreenshot(options: ScreenshotOptions): Promise<ScreenshotValue | null>;\n}\n\nexport interface ScreenshotOptions {\n /**\n * The desired size (here width) of the screenshot\n */\n size: number;\n /**\n * The quality of the screenshot between 0-100\n */\n quality: number;\n /**\n * The name of the file to save\n */\n name?: string;\n}\n\nexport interface ScreenshotValue {\n /**\n * The base64 string of the screenshot.\n * Can be null\n */\n base64?: string;\n /**\n * The file uri where the image is saved\n * Can be null\n */\n URI?: string;\n}\n"]}
package/dist/esm/web.js CHANGED
@@ -29,10 +29,19 @@ export class CapacitorScreenshotWeb extends WebPlugin {
29
29
  // set the canvas size with the video size
30
30
  this.captureCanvas.width = this.videoCapture.videoWidth;
31
31
  this.captureCanvas.height = this.videoCapture.videoHeight;
32
+ let newWidth = this.captureCanvas.width;
33
+ let newHeight = this.captureCanvas.height;
34
+ if (options.size) {
35
+ newWidth = options.size;
36
+ newHeight =
37
+ (this.captureCanvas.height * newWidth) / this.captureCanvas.width;
38
+ this.captureCanvas.width = newWidth;
39
+ this.captureCanvas.height = newHeight;
40
+ }
32
41
  // draw the video into canvas
33
42
  this.captureCanvas
34
43
  .getContext('2d')
35
- .drawImage(this.videoCapture, 0, 0);
44
+ .drawImage(this.videoCapture, 0, 0, newWidth, newHeight);
36
45
  let quality = 1.0;
37
46
  if (options.quality) {
38
47
  quality = options.quality / 100;
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,MAAM,OAAO,sBACX,SAAQ,SAAS;IAOjB,KAAK,CAAC,aAAa,CACjB,OAA0B;QAE1B,IAAI;YACF,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;gBACvB,sBAAsB;gBAEtB,uBAAuB;gBACvB,MAAM,YAAY,GAAG,SAAS,CAAC,YAAmB,CAAC;gBACnD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC;gBAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC;gBAE9D,oCAAoC;gBACpC,IAAI,CAAC,aAAa,GAAG,MAAM,YAAY,CAAC,eAAe,CAAC;oBACtD,gBAAgB,EAAE,IAAI;oBACtB,KAAK,EAAE,KAAK;oBACZ,KAAK,EAAE;wBACL,KAAK;wBACL,MAAM;qBACP;iBACF,CAAC,CAAC;gBACH,qBAAqB;gBACrB,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;gBACpD,kBAAkB;gBAClB,IAAI,CAAC,aAAa,GAA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AO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,UAAU,GAAa,EAAE,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC;SACb;IACH,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapacitorScreenshotPlugin,\n ScreenshotOptions,\n ScreenshotValue,\n} from './definitions';\n\nexport class CapacitorScreenshotWeb\n extends WebPlugin\n implements CapacitorScreenshotPlugin\n{\n private captureStream: any;\n private videoCapture: any;\n private captureCanvas: any;\n\n async getScreenshot(\n options: ScreenshotOptions,\n ): Promise<ScreenshotValue | null> {\n try {\n if (!this.captureStream) {\n // display a message ?\n\n // get the media device\n const mediaDevices = navigator.mediaDevices as any;\n const width = screen.width * (window.devicePixelRatio || 1);\n const height = screen.height * (window.devicePixelRatio || 1);\n\n // start sharing screen (ask for it)\n this.captureStream = await mediaDevices.getDisplayMedia({\n preferCurrentTab: true,\n audio: false,\n video: {\n width,\n height,\n },\n });\n // create a video tag\n this.videoCapture = document.createElement('video');\n // create a canvas\n this.captureCanvas = document.createElement('canvas');\n }\n\n return new Promise<any>(resolve => {\n const callbackLoadedMetadata = () => {\n // unbind from loaded metadata\n this.videoCapture.removeEventListener(\n 'loadedmetadata',\n callbackLoadedMetadata,\n );\n // set the canvas size with the video size\n this.captureCanvas.width = this.videoCapture.videoWidth;\n this.captureCanvas.height = this.videoCapture.videoHeight;\n // draw the video into canvas\n this.captureCanvas\n .getContext('2d')\n .drawImage(this.videoCapture, 0, 0);\n let quality = 1.0;\n if (options.quality) {\n quality = options.quality / 100;\n }\n // get the image of the canvas\n const frame = this.captureCanvas.toDataURL('image/jpeg', quality);\n // pause the video\n this.videoCapture.pause();\n\n // return the image\n resolve({ base64: frame });\n };\n\n // bind on loaded metadata to draw the video when the video is ready\n this.videoCapture.onloadedmetadata = callbackLoadedMetadata;\n // set the src of the video\n this.videoCapture.srcObject = this.captureStream;\n // play the video\n this.videoCapture.play();\n });\n } catch (err) {\n console.error(`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AAG,IAAI,CAAC,aAAa,CAAC;gBACjD,iBAAiB;gBACjB,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;YAC3B,CAAC,CAAC,CAAC;SACJ;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,UAAU,GAAa,EAAE,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC;SACb;IACH,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapacitorScreenshotPlugin,\n ScreenshotOptions,\n ScreenshotValue,\n} from './definitions';\n\nexport class CapacitorScreenshotWeb\n extends WebPlugin\n implements CapacitorScreenshotPlugin\n{\n private captureStream: any;\n private videoCapture: any;\n private captureCanvas: any;\n\n async getScreenshot(\n options: ScreenshotOptions,\n ): Promise<ScreenshotValue | null> {\n try {\n if (!this.captureStream) {\n // display a message ?\n\n // get the media device\n const mediaDevices = navigator.mediaDevices as any;\n const width = screen.width * (window.devicePixelRatio || 1);\n const height = screen.height * (window.devicePixelRatio || 1);\n\n // start sharing screen (ask for it)\n this.captureStream = await mediaDevices.getDisplayMedia({\n preferCurrentTab: true,\n audio: false,\n video: {\n width,\n height,\n },\n });\n // create a video tag\n this.videoCapture = document.createElement('video');\n // create a canvas\n this.captureCanvas = document.createElement('canvas');\n }\n\n return new Promise<any>(resolve => {\n const callbackLoadedMetadata = () => {\n // unbind from loaded metadata\n this.videoCapture.removeEventListener(\n 'loadedmetadata',\n callbackLoadedMetadata,\n );\n // set the canvas size with the video size\n this.captureCanvas.width = this.videoCapture.videoWidth;\n this.captureCanvas.height = this.videoCapture.videoHeight;\n let newWidth = this.captureCanvas.width;\n let newHeight = this.captureCanvas.height;\n if (options.size) {\n newWidth = options.size;\n newHeight =\n (this.captureCanvas.height * newWidth) / this.captureCanvas.width;\n this.captureCanvas.width = newWidth;\n this.captureCanvas.height = newHeight;\n }\n // draw the video into canvas\n this.captureCanvas\n .getContext('2d')\n .drawImage(this.videoCapture, 0, 0, newWidth, newHeight);\n let quality = 1.0;\n if (options.quality) {\n quality = options.quality / 100;\n }\n // get the image of the canvas\n const frame = this.captureCanvas.toDataURL('image/jpeg', quality);\n // pause the video\n this.videoCapture.pause();\n\n // return the image\n resolve({ base64: frame });\n };\n\n // bind on loaded metadata to draw the video when the video is ready\n this.videoCapture.onloadedmetadata = callbackLoadedMetadata;\n // set the src of the video\n this.videoCapture.srcObject = this.captureStream;\n // play the video\n this.videoCapture.play();\n });\n } catch (err) {\n console.error(`Error: ${err as string}`);\n return null;\n }\n }\n}\n"]}
@@ -38,10 +38,19 @@ class CapacitorScreenshotWeb extends core.WebPlugin {
38
38
  // set the canvas size with the video size
39
39
  this.captureCanvas.width = this.videoCapture.videoWidth;
40
40
  this.captureCanvas.height = this.videoCapture.videoHeight;
41
+ let newWidth = this.captureCanvas.width;
42
+ let newHeight = this.captureCanvas.height;
43
+ if (options.size) {
44
+ newWidth = options.size;
45
+ newHeight =
46
+ (this.captureCanvas.height * newWidth) / this.captureCanvas.width;
47
+ this.captureCanvas.width = newWidth;
48
+ this.captureCanvas.height = newHeight;
49
+ }
41
50
  // draw the video into canvas
42
51
  this.captureCanvas
43
52
  .getContext('2d')
44
- .drawImage(this.videoCapture, 0, 0);
53
+ .drawImage(this.videoCapture, 0, 0, newWidth, newHeight);
45
54
  let quality = 1.0;
46
55
  if (options.quality) {
47
56
  quality = options.quality / 100;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorScreenshot = registerPlugin('CapacitorScreenshot', {\n web: () => import('./web').then(m => new m.CapacitorScreenshotWeb()),\n});\nexport * from './definitions';\nexport { CapacitorScreenshot };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorScreenshotWeb extends WebPlugin {\n async getScreenshot(options) {\n try {\n if (!this.captureStream) {\n // display a message ?\n // get the media device\n const mediaDevices = navigator.mediaDevices;\n const width = screen.width * (window.devicePixelRatio || 1);\n const height = screen.height * (window.devicePixelRatio || 1);\n // start sharing screen (ask for it)\n this.captureStream = await mediaDevices.getDisplayMedia({\n preferCurrentTab: true,\n audio: false,\n video: {\n width,\n height,\n },\n });\n // create a video tag\n this.videoCapture = document.createElement('video');\n // create a canvas\n this.captureCanvas = document.createElement('canvas');\n }\n return new Promise(resolve => {\n const callbackLoadedMetadata = () => {\n // unbind from loaded metadata\n this.videoCapture.removeEventListener('loadedmetadata', callbackLoadedMetadata);\n // set the canvas size with the video size\n this.captureCanvas.width = this.videoCapture.videoWidth;\n this.captureCanvas.height = this.videoCapture.videoHeight;\n // draw the video into canvas\n this.captureCanvas\n .getContext('2d')\n .drawImage(this.videoCapture, 0, 0);\n let quality = 1.0;\n if (options.quality) {\n quality = options.quality / 100;\n }\n // get the image of the canvas\n const frame = this.captureCanvas.toDataURL('image/jpeg', quality);\n // pause the video\n this.videoCapture.pause();\n // return the image\n resolve({ base64: frame });\n };\n // bind on loaded metadata to draw the video when the video is ready\n this.videoCapture.onloadedmetadata = callbackLoadedMetadata;\n // set the src of the video\n this.videoCapture.srcObject = this.captureStream;\n // play the video\n this.videoCapture.play();\n });\n }\n catch (err) {\n console.error(`Error: ${err}`);\n return null;\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,mBAAmB,GAAGA,mBAAc,CAAC,qBAAqB,EAAE;AAClE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,sBAAsB,EAAE,CAAC;AACxE,CAAC;;ACFM,MAAM,sBAAsB,SAASC,cAAS,CAAC;AACtD,IAAI,MAAM,aAAa,CAAC,OAAO,EAAE;AACjC,QAAQ,IAAI;AACZ,YAAY,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;AACrC;AACA;AACA,gBAAgB,MAAM,YAAY,GAAG,SAAS,CAAC,YA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B,IAAI,OAAO,CAAC,OAAO,EAAE;AACzC,wBAAwB,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,GAAG,CAAC;AACxD,qBAAqB;AACrB;AACA,oBAAoB,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACtF;AACA,oBAAoB,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;AAC9C;AACA,oBAAoB,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAC/C,iBAAiB,CAAC;AAClB;AACA,gBAAgB,IAAI,CAAC,YAAY,CAAC,gBAAgB,GAAG,sBAAsB,CAAC;AAC5E;AACA,gBAAgB,IAAI,CAAC,YAAY,CAAC,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC;AACjE;AACA,gBAAgB,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;AACzC,aAAa,CAAC,CAAC;AACf,SAAS;AACT,QAAQ,OAAO,GAAG,EAAE;AACpB,YAAY,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AAC3C,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorScreenshot = registerPlugin('CapacitorScreenshot', {\n web: () => import('./web').then(m => new m.CapacitorScreenshotWeb()),\n});\nexport * from './definitions';\nexport { CapacitorScreenshot };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorScreenshotWeb extends WebPlugin {\n async getScreenshot(options) {\n try {\n if (!this.captureStream) {\n // display a message ?\n // get the media device\n const mediaDevices = navigator.mediaDevices;\n const width = screen.width * (window.devicePixelRatio || 1);\n const height = screen.height * (window.devicePixelRatio || 1);\n // start sharing screen (ask for it)\n this.captureStream = await mediaDevices.getDisplayMedia({\n preferCurrentTab: true,\n audio: false,\n video: {\n width,\n height,\n },\n });\n // create a video tag\n this.videoCapture = document.createElement('video');\n // create a canvas\n this.captureCanvas = document.createElement('canvas');\n }\n return new Promise(resolve => {\n const callbackLoadedMetadata = () => {\n // unbind from loaded metadata\n this.videoCapture.removeEventListener('loadedmetadata', callbackLoadedMetadata);\n // set the canvas size with the video size\n this.captureCanvas.width = this.videoCapture.videoWidth;\n this.captureCanvas.height = this.videoCapture.videoHeight;\n let newWidth = this.captureCanvas.width;\n let newHeight = this.captureCanvas.height;\n if (options.size) {\n newWidth = options.size;\n newHeight =\n (this.captureCanvas.height * newWidth) / this.captureCanvas.width;\n this.captureCanvas.width = newWidth;\n this.captureCanvas.height = newHeight;\n }\n // draw the video into canvas\n this.captureCanvas\n .getContext('2d')\n .drawImage(this.videoCapture, 0, 0, newWidth, newHeight);\n let quality = 1.0;\n if (options.quality) {\n quality = options.quality / 100;\n }\n // get the image of the canvas\n const frame = this.captureCanvas.toDataURL('image/jpeg', quality);\n // pause the video\n this.videoCapture.pause();\n // return the image\n resolve({ base64: frame });\n };\n // bind on loaded metadata to draw the video when the video is ready\n this.videoCapture.onloadedmetadata = callbackLoadedMetadata;\n // set the src of the video\n this.videoCapture.srcObject = this.captureStream;\n // play the video\n this.videoCapture.play();\n });\n }\n catch (err) {\n console.error(`Error: ${err}`);\n return null;\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,mBAAmB,GAAGA,mBAAc,CAAC,qBAAqB,EAAE;AAClE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,sBAAsB,EAAE,CAAC;AACxE,CAAC;;ACFM,MAAM,sBAAsB,SAASC,cAAS,CAAC;AACtD,IAAI,MAAM,aAAa,CAAC,OAAO,EAAE;AACjC,QAAQ,IAAI;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,CAAC,CAAC;AACf,SAAS;AACT,QAAQ,OAAO,GAAG,EAAE;AACpB,YAAY,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AAC3C,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -35,10 +35,19 @@ var capacitorCapacitorScreenshot = (function (exports, core) {
35
35
  // set the canvas size with the video size
36
36
  this.captureCanvas.width = this.videoCapture.videoWidth;
37
37
  this.captureCanvas.height = this.videoCapture.videoHeight;
38
+ let newWidth = this.captureCanvas.width;
39
+ let newHeight = this.captureCanvas.height;
40
+ if (options.size) {
41
+ newWidth = options.size;
42
+ newHeight =
43
+ (this.captureCanvas.height * newWidth) / this.captureCanvas.width;
44
+ this.captureCanvas.width = newWidth;
45
+ this.captureCanvas.height = newHeight;
46
+ }
38
47
  // draw the video into canvas
39
48
  this.captureCanvas
40
49
  .getContext('2d')
41
- .drawImage(this.videoCapture, 0, 0);
50
+ .drawImage(this.videoCapture, 0, 0, newWidth, newHeight);
42
51
  let quality = 1.0;
43
52
  if (options.quality) {
44
53
  quality = options.quality / 100;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorScreenshot = registerPlugin('CapacitorScreenshot', {\n web: () => import('./web').then(m => new m.CapacitorScreenshotWeb()),\n});\nexport * from './definitions';\nexport { CapacitorScreenshot };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorScreenshotWeb extends WebPlugin {\n async getScreenshot(options) {\n try {\n if (!this.captureStream) {\n // display a message ?\n // get the media device\n const mediaDevices = navigator.mediaDevices;\n const width = screen.width * (window.devicePixelRatio || 1);\n const height = screen.height * (window.devicePixelRatio || 1);\n // start sharing screen (ask for it)\n this.captureStream = await mediaDevices.getDisplayMedia({\n preferCurrentTab: true,\n audio: false,\n video: {\n width,\n height,\n },\n });\n // create a video tag\n this.videoCapture = document.createElement('video');\n // create a canvas\n this.captureCanvas = document.createElement('canvas');\n }\n return new Promise(resolve => {\n const callbackLoadedMetadata = () => {\n // unbind from loaded metadata\n this.videoCapture.removeEventListener('loadedmetadata', callbackLoadedMetadata);\n // set the canvas size with the video size\n this.captureCanvas.width = this.videoCapture.videoWidth;\n this.captureCanvas.height = this.videoCapture.videoHeight;\n // draw the video into canvas\n this.captureCanvas\n .getContext('2d')\n .drawImage(this.videoCapture, 0, 0);\n let quality = 1.0;\n if (options.quality) {\n quality = options.quality / 100;\n }\n // get the image of the canvas\n const frame = this.captureCanvas.toDataURL('image/jpeg', quality);\n // pause the video\n this.videoCapture.pause();\n // return the image\n resolve({ base64: frame });\n };\n // bind on loaded metadata to draw the video when the video is ready\n this.videoCapture.onloadedmetadata = callbackLoadedMetadata;\n // set the src of the video\n this.videoCapture.srcObject = this.captureStream;\n // play the video\n this.videoCapture.play();\n });\n }\n catch (err) {\n console.error(`Error: ${err}`);\n return null;\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,mBAAmB,GAAGA,mBAAc,CAAC,qBAAqB,EAAE;IAClE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,sBAAsB,EAAE,CAAC;IACxE,CAAC;;ICFM,MAAM,sBAAsB,SAASC,cAAS,CAAC;IACtD,IAAI,MAAM,aAAa,CAAC,OAAO,EAAE;IACjC,QAAQ,IAAI;IACZ,YAAY,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;IACrC;IACA;IACA,gBAAgB,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY,CAAC;IAC5D,gBAAgB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC;IAC5E,gBA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AAoB,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACtF;IACA,oBAAoB,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;IAC9C;IACA,oBAAoB,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/C,iBAAiB,CAAC;IAClB;IACA,gBAAgB,IAAI,CAAC,YAAY,CAAC,gBAAgB,GAAG,sBAAsB,CAAC;IAC5E;IACA,gBAAgB,IAAI,CAAC,YAAY,CAAC,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC;IACjE;IACA,gBAAgB,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IACzC,aAAa,CAAC,CAAC;IACf,SAAS;IACT,QAAQ,OAAO,GAAG,EAAE;IACpB,YAAY,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3C,YAAY,OAAO,IAAI,CAAC;IACxB,SAAS;IACT,KAAK;IACL;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorScreenshot = registerPlugin('CapacitorScreenshot', {\n web: () => import('./web').then(m => new m.CapacitorScreenshotWeb()),\n});\nexport * from './definitions';\nexport { CapacitorScreenshot };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorScreenshotWeb extends WebPlugin {\n async getScreenshot(options) {\n try {\n if (!this.captureStream) {\n // display a message ?\n // get the media device\n const mediaDevices = navigator.mediaDevices;\n const width = screen.width * (window.devicePixelRatio || 1);\n const height = screen.height * (window.devicePixelRatio || 1);\n // start sharing screen (ask for it)\n this.captureStream = await mediaDevices.getDisplayMedia({\n preferCurrentTab: true,\n audio: false,\n video: {\n width,\n height,\n },\n });\n // create a video tag\n this.videoCapture = document.createElement('video');\n // create a canvas\n this.captureCanvas = document.createElement('canvas');\n }\n return new Promise(resolve => {\n const callbackLoadedMetadata = () => {\n // unbind from loaded metadata\n this.videoCapture.removeEventListener('loadedmetadata', callbackLoadedMetadata);\n // set the canvas size with the video size\n this.captureCanvas.width = this.videoCapture.videoWidth;\n this.captureCanvas.height = this.videoCapture.videoHeight;\n let newWidth = this.captureCanvas.width;\n let newHeight = this.captureCanvas.height;\n if (options.size) {\n newWidth = options.size;\n newHeight =\n (this.captureCanvas.height * newWidth) / this.captureCanvas.width;\n this.captureCanvas.width = newWidth;\n this.captureCanvas.height = newHeight;\n }\n // draw the video into canvas\n this.captureCanvas\n .getContext('2d')\n .drawImage(this.videoCapture, 0, 0, newWidth, newHeight);\n let quality = 1.0;\n if (options.quality) {\n quality = options.quality / 100;\n }\n // get the image of the canvas\n const frame = this.captureCanvas.toDataURL('image/jpeg', quality);\n // pause the video\n this.videoCapture.pause();\n // return the image\n resolve({ base64: frame });\n };\n // bind on loaded metadata to draw the video when the video is ready\n this.videoCapture.onloadedmetadata = callbackLoadedMetadata;\n // set the src of the video\n this.videoCapture.srcObject = this.captureStream;\n // play the video\n this.videoCapture.play();\n });\n }\n catch (err) {\n console.error(`Error: ${err}`);\n return null;\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,mBAAmB,GAAGA,mBAAc,CAAC,qBAAqB,EAAE;IAClE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,sBAAsB,EAAE,CAAC;IACxE,CAAC;;ICFM,MAAM,sBAAsB,SAASC,cAAS,CAAC;IACtD,IAAI,MAAM,aAAa,CAAC,OAAO,EAAE;IACjC,QAAQ,IAAI;IACZ,YAAY,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;IACrC;IACA;IACA,gBAAgB,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY,CAAC;IAC5D,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AAC,CAAC,CAAC;IAC3C,YAAY,OAAO,IAAI,CAAC;IACxB,SAAS;IACT,KAAK;IACL;;;;;;;;;;;;;;;;;"}
@@ -13,6 +13,7 @@ public class CapacitorScreenshotPlugin: CAPPlugin {
13
13
 
14
14
  let quality = ((call.getDouble("quality") ?? 100) / 100)
15
15
  let filename = (call.getString("name") ?? "screenshot")
16
+
16
17
  DispatchQueue.main.async {
17
18
  let config = WKSnapshotConfiguration()
18
19
  config.rect = self.webView!.frame
@@ -22,7 +23,22 @@ public class CapacitorScreenshotPlugin: CAPPlugin {
22
23
  if error != nil {
23
24
  return
24
25
  }
25
- guard let imageData = image!.jpegData(compressionQuality: quality) else {return}
26
+
27
+ let imageSize = image?.size
28
+ var newImage = image
29
+ if imageSize != nil {
30
+ let size = (call.getDouble("size") ?? Double(imageSize!.width))
31
+
32
+ // compute the new size of the image
33
+ let width = Double.minimum(imageSize!.width, size)
34
+ let height = imageSize!.height * width / imageSize!.width
35
+ let newSize: CGSize = CGSize(width: width, height: height)
36
+
37
+ // resize the image
38
+ newImage = image?.imageWith(newSize: newSize)
39
+ }
40
+
41
+ guard let imageData = newImage!.jpegData(compressionQuality: quality) else {return}
26
42
  let base64Result = imageData.base64EncodedString()
27
43
  let file = "data:image/png;base64," + base64Result
28
44
 
@@ -46,4 +62,15 @@ public class CapacitorScreenshotPlugin: CAPPlugin {
46
62
  })
47
63
  }
48
64
  }
65
+
66
+ }
67
+
68
+ extension UIImage {
69
+ func imageWith(newSize: CGSize) -> UIImage {
70
+ let image = UIGraphicsImageRenderer(size: newSize).image { _ in
71
+ draw(in: CGRect(origin: .zero, size: newSize))
72
+ }
73
+
74
+ return image.withRenderingMode(renderingMode)
75
+ }
49
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuiface/capacitor-plugin-screenshot",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Capacitor plugin to take screenshot for iOS and Android devices",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",