@intuiface/capacitor-plugin-screenshot 1.0.1 → 2.0.0
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 +11 -5
- package/android/build.gradle +3 -3
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/intuiface/plugins/screenshot/CapacitorScreenshotPlugin.java +44 -36
- package/dist/docs.json +7 -0
- package/dist/esm/definitions.d.ts +4 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.js +10 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +10 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +10 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorScreenshotPlugin.swift +28 -1
- package/package.json +7 -7
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
|
-
| **`
|
65
|
-
| **`
|
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
|
|
@@ -70,7 +71,7 @@ Function to take a screenshot
|
|
70
71
|
|
71
72
|
## iOS
|
72
73
|
|
73
|
-
iOS version
|
74
|
+
iOS version 13+ is supported.
|
74
75
|
|
75
76
|
Nothing more to do, it should work by calling the `getScreenshot` function.
|
76
77
|
|
@@ -84,6 +85,11 @@ To be able to take screenshot on Android, you have to declare a foreground servi
|
|
84
85
|
```xml
|
85
86
|
<service android:enabled="true" android:foregroundServiceType="mediaProjection" android:name="com.intuiface.plugins.screenshot.ScreenCaptureService" />
|
86
87
|
```
|
88
|
+
And also add permissions :
|
89
|
+
```xml
|
90
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
91
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
|
92
|
+
```
|
87
93
|
|
88
94
|
The foreground service will ask you to cast your screen and this is mandatory to take screenshot with the `MediaProjection` API.
|
89
95
|
|
package/android/build.gradle
CHANGED
@@ -11,7 +11,7 @@ buildscript {
|
|
11
11
|
mavenCentral()
|
12
12
|
}
|
13
13
|
dependencies {
|
14
|
-
classpath 'com.android.tools.build:gradle:8.
|
14
|
+
classpath 'com.android.tools.build:gradle:8.2.1'
|
15
15
|
}
|
16
16
|
}
|
17
17
|
|
@@ -19,10 +19,10 @@ apply plugin: 'com.android.library'
|
|
19
19
|
|
20
20
|
android {
|
21
21
|
namespace "com.intuiface.plugins.screenshot"
|
22
|
-
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
23
23
|
defaultConfig {
|
24
24
|
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
25
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
26
26
|
versionCode 1
|
27
27
|
versionName "1.0"
|
28
28
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
package/android/src/main/java/com/intuiface/plugins/screenshot/CapacitorScreenshotPlugin.java
CHANGED
@@ -41,9 +41,15 @@ public class CapacitorScreenshotPlugin extends Plugin {
|
|
41
41
|
private ActivityResultLauncher<Intent> mediaProjectionActivityLauncher;
|
42
42
|
|
43
43
|
private PluginCall savedCall;
|
44
|
+
private VirtualDisplay virtualDisplay;
|
45
|
+
private Handler handler;
|
44
46
|
|
45
47
|
@Override
|
46
48
|
public void load() {
|
49
|
+
HandlerThread handlerThread = new HandlerThread("ScreenshotThread");
|
50
|
+
handlerThread.start();
|
51
|
+
handler = new Handler(handlerThread.getLooper());
|
52
|
+
|
47
53
|
mediaProjectionActivityLauncher =
|
48
54
|
getActivity()
|
49
55
|
.registerForActivityResult(
|
@@ -63,9 +69,30 @@ public class CapacitorScreenshotPlugin extends Plugin {
|
|
63
69
|
|
64
70
|
@PluginMethod
|
65
71
|
public void getScreenshot(PluginCall call) {
|
66
|
-
if (mediaProjection != null) {
|
72
|
+
if (mediaProjection != null && virtualDisplay != null) {
|
67
73
|
savedCall = call;
|
68
|
-
|
74
|
+
|
75
|
+
final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
|
76
|
+
int screenWidth = metrics.widthPixels;
|
77
|
+
int screenHeight = metrics.heightPixels;
|
78
|
+
// Create an ImageReader to capture the screen content
|
79
|
+
ImageReader imageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 1);
|
80
|
+
// Handle the captured images from the ImageReader
|
81
|
+
imageReader.setOnImageAvailableListener(
|
82
|
+
reader -> {
|
83
|
+
Image image = imageReader.acquireLatestImage();
|
84
|
+
if (image != null) {
|
85
|
+
// Process the captured image
|
86
|
+
processScreenshot(image);
|
87
|
+
// Release the image resources
|
88
|
+
image.close();
|
89
|
+
}
|
90
|
+
},
|
91
|
+
handler
|
92
|
+
);
|
93
|
+
|
94
|
+
// set the new surface to get the capture
|
95
|
+
virtualDisplay.setSurface(imageReader.getSurface());
|
69
96
|
} else {
|
70
97
|
ScreenCaptureManager screenCaptureManager = new ScreenCaptureManager(getContext());
|
71
98
|
screenCaptureManager.startForeground();
|
@@ -94,47 +121,27 @@ public class CapacitorScreenshotPlugin extends Plugin {
|
|
94
121
|
}
|
95
122
|
|
96
123
|
private void startScreenshotCapture(MediaProjection mediaProjection) {
|
97
|
-
HandlerThread handlerThread = new HandlerThread("ScreenshotThread");
|
98
|
-
handlerThread.start();
|
99
|
-
|
100
124
|
final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
|
101
125
|
int screenWidth = metrics.widthPixels;
|
102
126
|
int screenHeight = metrics.heightPixels;
|
103
|
-
|
104
|
-
Handler handler = new Handler(handlerThread.getLooper());
|
105
|
-
|
106
127
|
int screenDensity = metrics.densityDpi;
|
107
128
|
|
108
129
|
// Create an ImageReader to capture the screen content
|
109
|
-
@SuppressLint("WrongConstant")
|
110
130
|
ImageReader imageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 1);
|
131
|
+
|
132
|
+
mediaProjection.registerCallback(new MediaProjection.Callback() {}, null);
|
111
133
|
// Create a VirtualDisplay using the mediaProjection and imageReader
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
// Handle the captured images from the ImageReader
|
124
|
-
imageReader.setOnImageAvailableListener(
|
125
|
-
reader -> {
|
126
|
-
Image image = imageReader.acquireLatestImage();
|
127
|
-
if (image != null) {
|
128
|
-
// Process the captured image
|
129
|
-
processScreenshot(image);
|
130
|
-
// Release the image resources
|
131
|
-
image.close();
|
132
|
-
|
133
|
-
virtualDisplay.release();
|
134
|
-
}
|
135
|
-
},
|
136
|
-
handler
|
137
|
-
);
|
134
|
+
this.virtualDisplay =
|
135
|
+
mediaProjection.createVirtualDisplay(
|
136
|
+
"ScreenCapture",
|
137
|
+
screenWidth,
|
138
|
+
screenHeight,
|
139
|
+
screenDensity,
|
140
|
+
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
|
141
|
+
imageReader.getSurface(),
|
142
|
+
null,
|
143
|
+
handler
|
144
|
+
);
|
138
145
|
}
|
139
146
|
|
140
147
|
private void processScreenshot(Image image) {
|
@@ -194,8 +201,9 @@ public class CapacitorScreenshotPlugin extends Plugin {
|
|
194
201
|
// generate the final bitmap at the right size from the bitmap created
|
195
202
|
bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height);
|
196
203
|
|
204
|
+
int desiredWidth = savedCall.getInt("size", width);
|
197
205
|
// scale but keep ratio
|
198
|
-
int scaledWidth = Math.min(width,
|
206
|
+
int scaledWidth = Math.min(width, desiredWidth);
|
199
207
|
int scaledHeight = height * scaledWidth / width;
|
200
208
|
bitmap = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, false);
|
201
209
|
|
package/dist/docs.json
CHANGED
@@ -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;
|
package/dist/esm/web.js.map
CHANGED
@@ -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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AAC,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"]}
|
package/dist/plugin.cjs.js
CHANGED
@@ -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;
|
package/dist/plugin.cjs.js.map
CHANGED
@@ -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;AACr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
|
+
{"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;AACZ,YAAY,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;AACrC;AACA;AACA,gBAAgB,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY,CAAC;AAC5D,gBAAgB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC;AAC5E,gBAAgB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC;AAC9E;AACA,gBAAgB,IAAI,CAAC,aAAa,GAAG,MAAM,YAAY,CAAC,eAAe,CAAC;AACxE,oBAAoB,gBAAgB,EAAE,IAAI;AAC1C,oBAAoB,KAAK,EAAE,KAAK;AAChC,oBAAoB,KAAK,EAAE;AAC3B,wBAAwB,KAAK;AAC7B,wBAAwB,MAAM;AAC9B,qBAAqB;AACrB,iBAAiB,CAAC,CAAC;AACnB;AACA,gBAAgB,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACpE;AACA,gBAAgB,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AACtE,aAAa;AACb,YAAY,OAAO,IAAI,OAAO,CAAC,OAAO,IAA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C,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;;;;;;;;;"}
|
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;
|
package/dist/plugin.js.map
CHANGED
@@ -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//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,gBAAgB,EAAE,sBAAsB,CAAC,CAAC;IACpG;IACA,oBAAoB,IAAI,CAAC,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;IAC5E,oBAAoB,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC;IAC9E;IACA,oBAAoB,IAAI,CAAC,aAAa;IACtC,yBAAyB,UAAU,CAAC,IAAI,CAAC;IACzC,yBAAyB,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;
|
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,gBAAgB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC;IAC5E,gBAAgB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC;IAC9E;IACA,gBAAgB,IAAI,CAAC,aAAa,GAAG,MAAM,YAAY,CAAC,eAAe,CAAC;IACxE,oBAAoB,gBAAgB,EAAE,IAAI;IAC1C,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IACtC,yBAAyB,UAAU,CAAC,IAAI,CAAC;IACzC,yBAAyB,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IACjF,oBAAoB,IAAI,OAAO,GAAG,GAAG,CAAC;IACtC,oBAAoB,IAAI,OAAO,CAAC,OAAO,EAAE;IACzC,wBAAwB,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,GAAG,CAAC;IACxD,qBAAqB;IACrB;IACA,oBAAoB,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;;;;;;;;;;;;;;;;;"}
|
@@ -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
|
-
|
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": "
|
3
|
+
"version": "2.0.0",
|
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",
|
@@ -45,14 +45,14 @@
|
|
45
45
|
"prepare": "npx shx cp -u ./.githooks/* ./.git/hooks/"
|
46
46
|
},
|
47
47
|
"devDependencies": {
|
48
|
-
"@capacitor/android": "^
|
49
|
-
"@capacitor/core": "^
|
48
|
+
"@capacitor/android": "^6.0.0",
|
49
|
+
"@capacitor/core": "^6.0.0",
|
50
50
|
"@capacitor/docgen": "^0.0.18",
|
51
|
-
"@capacitor/ios": "^
|
52
|
-
"@ionic/eslint-config": "^0.
|
51
|
+
"@capacitor/ios": "^6.0.0",
|
52
|
+
"@ionic/eslint-config": "^0.4.0",
|
53
53
|
"@ionic/prettier-config": "^1.0.1",
|
54
54
|
"@ionic/swiftlint-config": "^1.1.2",
|
55
|
-
"eslint": "^
|
55
|
+
"eslint": "^8.57.0",
|
56
56
|
"prettier": "~2.3.0",
|
57
57
|
"prettier-plugin-java": "~1.0.2",
|
58
58
|
"rimraf": "^3.0.2",
|
@@ -61,7 +61,7 @@
|
|
61
61
|
"typescript": "~4.1.5"
|
62
62
|
},
|
63
63
|
"peerDependencies": {
|
64
|
-
"@capacitor/core": "^
|
64
|
+
"@capacitor/core": "^6.0.0"
|
65
65
|
},
|
66
66
|
"prettier": "@ionic/prettier-config",
|
67
67
|
"swiftlint": "@ionic/swiftlint-config",
|