@pilio/gemini-watermark-remover 1.0.10

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 (39) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +371 -0
  3. package/README_zh.md +371 -0
  4. package/bin/gwr.mjs +12 -0
  5. package/package.json +76 -0
  6. package/skills/gemini-watermark-remover/SKILL.md +28 -0
  7. package/skills/gemini-watermark-remover/agents/openai.yaml +3 -0
  8. package/skills/gemini-watermark-remover/references/inputs-and-outputs.md +9 -0
  9. package/skills/gemini-watermark-remover/references/limitations.md +5 -0
  10. package/skills/gemini-watermark-remover/references/usage.md +19 -0
  11. package/skills/gemini-watermark-remover/scripts/run.mjs +153 -0
  12. package/src/cli/gwrCli.js +17 -0
  13. package/src/cli/gwrRemoveCommand.js +317 -0
  14. package/src/core/adaptiveDetector.js +488 -0
  15. package/src/core/alphaMap.js +30 -0
  16. package/src/core/blendModes.js +70 -0
  17. package/src/core/candidateSelector.js +1446 -0
  18. package/src/core/canvasBlob.js +26 -0
  19. package/src/core/embeddedAlphaMaps.js +49 -0
  20. package/src/core/geminiSizeCatalog.js +239 -0
  21. package/src/core/multiPassRemoval.js +93 -0
  22. package/src/core/previewAlphaCalibration.js +822 -0
  23. package/src/core/restorationMetrics.js +251 -0
  24. package/src/core/selectionDebug.js +47 -0
  25. package/src/core/watermarkConfig.js +146 -0
  26. package/src/core/watermarkDecisionPolicy.js +163 -0
  27. package/src/core/watermarkDisplay.js +60 -0
  28. package/src/core/watermarkEngine.js +150 -0
  29. package/src/core/watermarkPresence.js +12 -0
  30. package/src/core/watermarkProcessor.js +875 -0
  31. package/src/core/workerClient.js +114 -0
  32. package/src/sdk/browser.d.ts +13 -0
  33. package/src/sdk/browser.js +29 -0
  34. package/src/sdk/image-data.d.ts +14 -0
  35. package/src/sdk/image-data.js +55 -0
  36. package/src/sdk/index.d.ts +144 -0
  37. package/src/sdk/index.js +8 -0
  38. package/src/sdk/node.d.ts +42 -0
  39. package/src/sdk/node.js +77 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jad
4
+ Copyright (c) 2024 AllenK (Kwyshell)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,371 @@
1
+ [中文文档](README_zh.md)
2
+
3
+ # Gemini Watermark Remover — Lossless Watermark Removal Tool
4
+
5
+ An open-source tool to **remove Gemini watermarks** from AI-generated images with high-fidelity, reproducible results on supported outputs. Built with pure JavaScript, the engine uses a mathematically exact **Reverse Alpha Blending** algorithm instead of unpredictable AI inpainting.
6
+
7
+ > **🚀 Looking for the `Online Gemini Watermark Remover (Recommended)`? Try [pilio.ai/gemini-watermark-remover](https://pilio.ai/gemini-watermark-remover)** — free, no install, works directly in your browser.
8
+
9
+ <p align="center">
10
+ <a href="https://pilio.ai/gemini-watermark-remover"><img src="https://img.shields.io/badge/🛠️_Online_Tool-pilio.ai-blue?style=for-the-badge" alt="Online Tool"></a>&nbsp;
11
+ <a href="https://gemini.pilio.ai/userscript/gemini-watermark-remover.user.js"><img src="https://img.shields.io/badge/🐒_Userscript-Install-green?style=for-the-badge" alt="Userscript"></a>&nbsp;
12
+ <a href="https://gemini.pilio.ai"><img src="https://img.shields.io/badge/🧪_Dev_Preview-gemini.pilio.ai-gray?style=for-the-badge" alt="Developer Preview"></a>
13
+ </p>
14
+
15
+ <p align="center">
16
+ <img src="https://count.getloli.com/@gemini-watermark-remover?name=gemini-watermark-remover&theme=minecraft&padding=7&offset=0&align=top&scale=1&pixelated=1&darkmode=auto" width="400">
17
+ </p>
18
+
19
+ ## Features
20
+
21
+ - ✅ **100% Local Processing** - All image processing happens locally in your browser or on your machine. Nothing is uploaded.
22
+ - ✅ **Mathematical Precision** - Based on the Reverse Alpha Blending formula, not "hallucinating" AI models.
23
+ - ✅ **Auto-Detection** - Automatically identifies watermark size and position using Gemini's known output catalog and local anchor search.
24
+ - ✅ **Flexible Usage** - Online tool for quick use, userscript for seamless Gemini page integration, CLI and Skill for scripting and automation.
25
+ - ✅ **Cross-Platform** - Works in modern browsers (Chrome, Firefox, Safari, Edge) and Node.js environments.
26
+
27
+ ## Gemini Watermark Removal Examples
28
+
29
+ <details open>
30
+ <summary>Click to Expand/Collapse Examples</summary>
31
+  
32
+ <p>lossless diff example</p>
33
+ <p><img src="docs/lossless_diff.webp"></p>
34
+
35
+
36
+ <p>example images</p>
37
+
38
+ | Original Image | Watermark Removed |
39
+ | :---: | :----: |
40
+ | <img src="docs/1.webp" width="400"> | <img src="docs/unwatermarked_1.webp" width="400"> |
41
+ | <img src="docs/2.webp" width="400"> | <img src="docs/unwatermarked_2.webp" width="400"> |
42
+ | <img src="docs/3.webp" width="400"> | <img src="docs/unwatermarked_3.webp" width="400"> |
43
+ | <img src="docs/4.webp" width="400"> | <img src="docs/unwatermarked_4.webp" width="400"> |
44
+ | <img src="docs/5.webp" width="400"> | <img src="docs/unwatermarked_5.webp" width="400"> |
45
+
46
+ </details>
47
+
48
+ ## ⚠️ Disclaimer
49
+
50
+ > [!WARNING]
51
+ > **USE AT YOUR OWN RISK**
52
+ >
53
+ > This tool modifies image files. While it is designed to work reliably, unexpected results may occur due to:
54
+ > - Variations in Gemini's watermark implementation
55
+ > - Corrupted or unusual image formats
56
+ > - Edge cases not covered by testing
57
+ >
58
+ > The author assumes no responsibility for any data loss, image corruption, or unintended modifications. By using this tool, you acknowledge that you understand these risks.
59
+
60
+ > [!NOTE]
61
+ > **Note**: Disable any fingerprint defender extensions (e.g., Canvas Fingerprint Defender) to avoid processing errors. https://github.com/GargantuaX/gemini-watermark-remover/issues/3
62
+
63
+ ## How to Remove Gemini Watermarks
64
+
65
+ ### Online Gemini Watermark Remover (Recommended)
66
+
67
+ For all users — the fastest and easiest way to remove Gemini watermarks from images:
68
+
69
+ 1. Open **[pilio.ai/gemini-watermark-remover](https://pilio.ai/gemini-watermark-remover)**.
70
+ 2. Drag and drop or click to select your Gemini-generated image.
71
+ 3. The engine will automatically process and remove the watermark.
72
+ 4. Download the cleaned image.
73
+
74
+ ### Userscript
75
+
76
+ 1. Install a userscript manager (e.g., Tampermonkey or Greasemonkey).
77
+ 2. Open [gemini-watermark-remover.user.js](https://gemini.pilio.ai/userscript/gemini-watermark-remover.user.js).
78
+ 3. The script will install automatically.
79
+ 4. Navigate to Gemini conversation pages.
80
+ 5. Eligible Gemini preview images on the page are replaced in place after processing.
81
+ 6. Gemini's native "Copy Image" and "Download Image" actions also return processed results.
82
+
83
+ Current userscript boundaries:
84
+
85
+ - no injected per-image controls
86
+ - no popup UI or bulk action surface
87
+ - page previews and native copy/download flows are both processed when the source image is reachable
88
+ - preview images keep the original visible while processing, with a subdued `Processing...` overlay
89
+ - if preview processing fails, the original page image stays visible and usable
90
+
91
+ ### Skill
92
+
93
+ For workflows that involve AI coding agents:
94
+
95
+ - `skills/gemini-watermark-remover/` contains a packaged Skill that agents can discover and invoke.
96
+ - Usage:
97
+
98
+ ```bash
99
+ node skills/gemini-watermark-remover/scripts/run.mjs remove <input> --output <file>
100
+ ```
101
+
102
+ - See [`SKILL.md`](skills/gemini-watermark-remover/SKILL.md) for agent integration details.
103
+
104
+ ### CLI
105
+
106
+ For scripting, CI, and local batch workflows, use the direct CLI:
107
+
108
+ ```bash
109
+ # repo-local
110
+ node bin/gwr.mjs remove <input> --output <file>
111
+
112
+ # installed globally
113
+ gwr remove <input> [--output <file> | --out-dir <dir>] [--overwrite] [--json]
114
+ ```
115
+
116
+ If you do not have `gwr` installed globally, use:
117
+
118
+ ```bash
119
+ pnpm dlx @pilio/gemini-watermark-remover remove <input> --output <file>
120
+ ```
121
+
122
+ ### Developer Preview
123
+
124
+ If you are a developer or contributor, you can preview the latest development build at [gemini.pilio.ai](https://gemini.pilio.ai). This site is a separate online preview/local-processing experience, distinct from the userscript. It may contain experimental features and is not intended for general use.
125
+
126
+ ## Development
127
+
128
+ ```bash
129
+ # Install dependencies
130
+ pnpm install
131
+
132
+ # Development build
133
+ pnpm dev
134
+
135
+ # Production build
136
+ pnpm build
137
+
138
+ # Local preview
139
+ pnpm serve
140
+ ```
141
+
142
+ ### Cloudflare Deployment Note
143
+
144
+ - `wrangler.toml` is the deployment config for the Cloudflare Worker/assets entry of this project.
145
+ - It points Wrangler at the built `dist/` directory and should be kept even if local tests or source imports do not reference it directly.
146
+
147
+ ### Tampermonkey Debugging on macOS
148
+
149
+ For the repo's fixed-profile workflow on macOS:
150
+
151
+ ```bash
152
+ # Build the latest userscript
153
+ pnpm build
154
+
155
+ # Start a local dist server if needed
156
+ pnpm dev
157
+
158
+ # Open the fixed Chrome profile with remote debugging enabled
159
+ ./scripts/open-fixed-chrome-profile.sh --url https://gemini.google.com/app
160
+ ```
161
+
162
+ Notes:
163
+
164
+ - the fixed profile lives under `.chrome-debug/tampermonkey-profile`
165
+ - default CDP port is `9226`
166
+ - default proxy is `http://127.0.0.1:7890`; disable it with `--proxy off` if not needed
167
+ - reinstall the latest userscript from the active local `pnpm dev` server
168
+ - `pnpm dev` starts probing from `http://127.0.0.1:4173/` and auto-increments if that port is already occupied
169
+ - if you are following a previously captured debugging session, its port may differ; trust the current `pnpm dev` output instead of hardcoding `4173`
170
+
171
+ ## SDK Usage (Advanced / Internal)
172
+
173
+ The package root still exposes an SDK, but this path is intended for advanced or internal integration scenarios:
174
+
175
+ ```javascript
176
+ import {
177
+ createWatermarkEngine,
178
+ removeWatermarkFromImage,
179
+ removeWatermarkFromImageData,
180
+ removeWatermarkFromImageDataSync,
181
+ } from '@pilio/gemini-watermark-remover';
182
+ ```
183
+
184
+ Use the pure-data API when you already have decoded `ImageData`:
185
+
186
+ ```javascript
187
+ const result = await removeWatermarkFromImageData(imageData, {
188
+ adaptiveMode: 'auto',
189
+ maxPasses: 4,
190
+ });
191
+
192
+ console.log(result.meta.decisionTier);
193
+ ```
194
+
195
+ Use the browser image API when you have an `HTMLImageElement` or `HTMLCanvasElement`:
196
+
197
+ ```javascript
198
+ const { canvas, meta } = await removeWatermarkFromImage(imageElement);
199
+ document.body.append(canvas);
200
+ console.log(meta.applied, meta.decisionTier);
201
+ ```
202
+
203
+ If you need to process many images, reuse a single engine instance so alpha maps stay cached:
204
+
205
+ ```javascript
206
+ const engine = await createWatermarkEngine();
207
+ const first = await removeWatermarkFromImageData(imageDataA, { engine });
208
+ const second = await removeWatermarkFromImageData(imageDataB, { engine });
209
+ ```
210
+
211
+ For Node.js integrations, use the dedicated subpath and inject your own decoder/encoder:
212
+
213
+ ```javascript
214
+ import { removeWatermarkFromBuffer } from '@pilio/gemini-watermark-remover/node';
215
+
216
+ const result = await removeWatermarkFromBuffer(inputBuffer, {
217
+ mimeType: 'image/png',
218
+ decodeImageData: yourDecodeFn,
219
+ encodeImageData: yourEncodeFn,
220
+ });
221
+ ```
222
+
223
+ ## Runtime Requirements
224
+
225
+ ### Web And Userscript
226
+
227
+ - modern Chrome / Firefox / Safari / Edge class browser
228
+ - ES modules
229
+ - Canvas API
230
+ - Async/Await
231
+ - TypedArray (`Float32Array`, `Uint8ClampedArray`)
232
+ - for the website copy button: `navigator.clipboard.write(...)` and `ClipboardItem`
233
+
234
+ ### CLI And Skill
235
+
236
+ - a local Node.js runtime capable of running this package and its dependencies
237
+ - filesystem access for local input/output paths
238
+ - for repo-local usage:
239
+
240
+ ```bash
241
+ node bin/gwr.mjs remove <input> --output <file>
242
+ node skills/gemini-watermark-remover/scripts/run.mjs remove <input> --output <file>
243
+ ```
244
+
245
+ - for distributed Skill usage, the local environment must be able to execute the packaged `gwr` CLI boundary
246
+
247
+ ## Testing
248
+
249
+ ```bash
250
+ # Run all tests
251
+ pnpm test
252
+ ```
253
+
254
+ Regression tests include image fixtures from `src/assets/samples/`.
255
+ Source samples stay in git.
256
+ Naming and retention rules for those fixtures are documented in `src/assets/samples/README.md`.
257
+ Complex preview/download validation notes are documented in `docs/complex-figure-verification-checklist.md`.
258
+ Local files under `src/assets/samples/fix/` are optional snapshot outputs for manual regression checks and are intentionally not tracked by git.
259
+
260
+ ## Release Notes
261
+
262
+ See [CHANGELOG.md](CHANGELOG.md) for release history and [RELEASE.md](RELEASE.md) for the local release checklist.
263
+
264
+ ## How Gemini Watermark Removal Works
265
+
266
+ ### The Gemini Watermarking Process
267
+
268
+ Gemini applies watermarks using standard alpha compositing:
269
+
270
+ $$watermarked = \alpha \cdot logo + (1 - \alpha) \cdot original$$
271
+
272
+ Where:
273
+ - `watermarked`: The pixel value with the watermark.
274
+ - `α`: The Alpha channel value (0.0 - 1.0).
275
+ - `logo`: The watermark logo color value (White = 255).
276
+ - `original`: The raw, original pixel value we want to recover.
277
+
278
+ ### The Reverse Solution
279
+
280
+ To remove the watermark, we solve for `original`:
281
+
282
+ $$original = \frac{watermarked - \alpha \cdot logo}{1 - \alpha}$$
283
+
284
+ By capturing the watermark on a known solid background, we reconstruct the exact Alpha map and apply the inverse formula to restore the original pixels with zero loss.
285
+
286
+ ## Detection Rules
287
+
288
+ The engine uses layered detection to locate and verify watermarks:
289
+
290
+ 1. **Size catalog lookup** — matches image dimensions against Gemini's known output sizes to predict watermark size and position.
291
+ 2. **Local anchor search** — refines the predicted position by scanning pixel data around the expected watermark region.
292
+ 3. **Restoration validation** — confirms the detected watermark is real before applying removal, avoiding false positives.
293
+
294
+ Default watermark configurations:
295
+
296
+ | Condition | Watermark Size | Right Margin | Bottom Margin |
297
+ | :--- | :--- | :--- | :--- |
298
+ | Larger Gemini outputs | 96×96 | 64px | 64px |
299
+ | Smaller Gemini outputs | 48×48 | 32px | 32px |
300
+
301
+ ## Project Structure
302
+
303
+ ```text
304
+ gemini-watermark-remover/
305
+ ├── bin/ # Published CLI entrypoint (`gwr`)
306
+ ├── public/
307
+ │ ├── index.html # Main web experience
308
+ │ ├── terms.html # Terms of service page
309
+ │ └── tampermonkey-worker-probe.* # Probe pages for userscript/debug flows
310
+ ├── skills/
311
+ │ └── gemini-watermark-remover/ # Distributable agent skill bundle
312
+ ├── src/
313
+ │ ├── assets/ # Calibration assets and regression samples
314
+ │ ├── cli/ # CLI argument parsing and file workflows
315
+ │ ├── core/ # Watermark math, scoring, and restoration
316
+ │ ├── i18n/ # Web locale resources
317
+ │ ├── page/ # Page-side runtime for Gemini page integration
318
+ │ ├── sdk/ # Advanced/internal SDK surface
319
+ │ ├── shared/ # Shared DOM, blob, and session helpers
320
+ │ ├── userscript/ # Userscript entrypoints and browser hooks
321
+ │ ├── workers/ # Worker runtime
322
+ │ ├── app.js # Website application entry point
323
+ │ └── i18n.js # Internationalization utilities
324
+ ├── tests/ # Unit, regression, packaging, and smoke tests
325
+ ├── scripts/ # Local automation and debug launchers
326
+ ├── dist/ # Build output directory
327
+ ├── wrangler.toml # Cloudflare Worker/assets deployment config
328
+ ├── build.js # Build script
329
+ └── package.json
330
+ ```
331
+
332
+ ## Architecture Overview
333
+
334
+ - `src/core/` contains watermark detection, candidate selection, restoration metrics, and the reverse-alpha removal pipeline.
335
+ - `src/userscript/`, `src/page/`, and `src/shared/` implement the real Gemini page integration, including preview replacement plus copy/download interception.
336
+ - `src/cli/` and `bin/gwr.mjs` expose file-oriented local automation.
337
+ - `skills/gemini-watermark-remover/` provides a distributable Skill that stays on the CLI boundary instead of importing repository internals directly.
338
+ - `src/sdk/` remains available for advanced/internal integrations, but it is no longer the primary public entrypoint.
339
+
340
+ ---
341
+
342
+ ## Limitations
343
+
344
+ - Only removes **Gemini visible watermarks** <small>(the semi-transparent logo in bottom-right)</small>
345
+ - Does not remove invisible/steganographic watermarks. <small>[(Learn more about SynthID)](https://support.google.com/gemini/answer/16722517)</small>
346
+ - Designed for Gemini's current visible watermark pattern <small>(validated against this repo through April 2026)</small>
347
+
348
+ ## Legal Disclaimer
349
+
350
+ This project is released under the **MIT License**.
351
+
352
+ The removal of watermarks may have legal implications depending on your jurisdiction and the intended use of the images. Users are solely responsible for ensuring their use of this tool complies with applicable laws, terms of service, and intellectual property rights.
353
+
354
+ The author does not condone or encourage the misuse of this tool for copyright infringement, misrepresentation, or any other unlawful purposes.
355
+
356
+ **THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM THE USE OF THIS SOFTWARE.**
357
+
358
+ ## Credits
359
+
360
+ This project is a JavaScript port of the [Gemini Watermark Tool](https://github.com/allenk/GeminiWatermarkTool) by Allen Kuo ([@allenk](https://github.com/allenk)).
361
+
362
+ The Reverse Alpha Blending method and calibrated watermark masks are based on the original work © 2024 AllenK (Kwyshell), licensed under MIT License.
363
+
364
+ ## Related Links
365
+
366
+ - [Gemini Watermark Tool](https://github.com/allenk/GeminiWatermarkTool)
367
+ - [Removing Gemini AI Watermarks: A Deep Dive into Reverse Alpha Blending](https://allenkuo.medium.com/removing-gemini-ai-watermarks-a-deep-dive-into-reverse-alpha-blending-bbbd83af2a3f)
368
+
369
+ ## License
370
+
371
+ [MIT License](./LICENSE)