水印图片

:information_source: Summary Automatically adds watermarks to user-uploaded images
:hammer_and_wrench: Repository GitHub - Arkshine/discourse-watermark-image
:question: Install Guide How to install a theme or theme component
:open_book: New to Discourse Themes? Beginner’s guide to using Discourse Themes

Install this theme component

Description

This theme component automatically adds watermarks to user-uploaded images. You can use either an image or a QR code as your watermark, with extensive customization options for position, appearance, and distribution patterns.

The component offers granular control through category and user group settings, allowing you to tailor the watermarking behavior to your community’s needs.

Please review the Important Notes section before implementation.

Features

  • High-performance processing using WebAssembly and Web Workers
  • Comprehensive image format support (PNG, JPEG, BMP, ICO, TIFF, WEBP)
  • Dynamic QR code watermark generation
  • Flexible sizing options (relative or absolute)
  • Versatile positioning system
  • Advanced appearance customization (opacity, rotation, scale, margin, etc.)
  • Multiple blending modes
  • Pattern distribution options (single, grid, diagonal, random)
  • Category and user group-specific settings
  • Live preview in settings panel

Settings

Setting Description
image The image to use as watermark.
Supported formats: PNG, JPEG, BMP, ICO, TIFF, WEBP.
Default: ""
size_mode How the watermark size is calculated:
- relative: Size is relative to the target’s image width.
- absolute: Applied at its original size.
Default: "relative"
relative_width The width of the watermark relative to the target image width (in %).
Only applies when the watermark size mode is set to relative.
Range: 1-100
Default: 10
absolute_scale Scale factor for original watermark size (only used in absolute mode). Min: 0.01
Default: 1
max_size Maximum size as percentage of image dimensions. Range: 1-100
Default: 50
position Position of the watermark: top-left, top-center, top-right, center-left, center, center-right, bottom-left, bottom-center, bottom-right
Default: "bottom-right"
margin_x Horizontal margin from the edge (in % of the target image)
Default: 0
margin_y Vertical margin from the edge (in % of the target image)
Default: 0
opacity Watermark opacity. Range: 1-100
Default: 100
rotate Rotation angle.
Range: -360 to 360 degrees
Default: 0
blend_mode How the watermark blends with the image: normal, overlay, over, atop, xor, plus, multiply, burn, difference, soft_light, screen, hard_light, dodge, exclusion, lighten, darken.
Default: "normal"
pattern Watermark repetition pattern: single, grid, diagonal, random
Default: "single"
pattern_allow_partial Allow partial watermarks at image edges
Default: true
pattern_max_count Maximum number of watermark repetitions (0 for infinite)
Default: 50
pattern_spacing Spacing between repeated watermarks (in % of the target image)
Default: 15
qrcode_enabled Enable QR code watermark
Default: false
qrcode_text Text to encode in QR code. Supports placeholders: {homepage}, {username}, {topic_url}
Default: ""
qrcode_color QR code color (hex or CSS variable)
Default: "var(--primary)"
qrcode_background_color QR code background color (hex or CSS variable)
Default: "var(--secondary)"
qrcode_quiet_zone Width of white space border around QR code (0-10 modules)
Default: 2
qrcode_error_correction Error correction level: Low (~7%), Medium (~15%), Quarter (~25%), High (~30%)
More information about error correction levels can be found here.
Default: "Medium"
categories Categories where watermark should be applied.
Default: ""
groups Groups the watermark should be applied to.
Default: "0"
skip_small_images Skip watermarking if image is below min_image_dimensions.
Default: false
min_image_dimensions Minimum dimensions required (width x height)
Default: "200x200"
allow_non_supported_uploads Allow image uploads to continue even when format is not supported
Default: false

Watermark Types

Image

The component supports multiple image formats: PNG, JPEG, BMP, ICO, TIFF, and WEBP.
See the FAQ section for important information about format support limitations.

QR Code

Generate dynamic QR codes with customizable content using these variables:

  • {homepage} - The URL of the homepage
  • {username} - The username of the user
  • {topic_url} - The URL of the topic

Important: When styling QR code watermarks, consider contrast and sizing. Poor contrast ratios or excessive styling can make QR codes unreadable. Always test your QR code watermarks with scanning apps.

Real-Time Preview

The settings panel includes a real-time preview feature, allowing you to see how your watermark configuration affects a sample image instantly.
The preview window offers several interactive features:

  • Resizable and movable preview window
  • Option to load a random sample image
  • Support for uploading your own test images from your device

On the desktop, it opens automatically. You can also open from the button at the bottom of the page:

More images



:warning: Important Notes

  • Original Images Are Not Preserved
    Watermarks are applied before server upload, and original images are not retained. Thoroughly test your watermark settings before deploying to production.

  • If testing in the admin panel, be careful not to validate your settings immediately. I would recommend creating a group or a category to be safe.

FAQ

Why are image formats limited?

While Discourse converts all uploads to JPEG, this TC watermarking occurs pre-upload on the original format, using specific image processing libraries. While post-upload watermarking is possible, it would require multiple upload/download cycles and affect the composer experience. I’m still exploring improvements to this workflow.

Why isn’t text watermarking supported?

Text watermarking would require extensive configuration options (font selection, styling, etc.) that would be difficult to implement effectively without a dedicated interface. Image watermarks provide more flexibility and can be created using existing design tools.

Roadmap

Future development plans may include:

  • Multiple watermark profiles [1]
  • Original image preservation [2]
  • Post-upload watermarking

Credits

This theme component is powered by:


  1. The upload input is partially supported with the Object settings type – it can’t be done in a TC at the moment. ↩︎

  2. May require plugin development. ↩︎

24 个赞

这是第一个版本,我预计会缺少一些功能。期待您的任何反馈! :+1:

7 个赞

感谢您的组件。此组件是否处理图像?此组件是否能将图像压缩到比原始图像更好的尺寸?

5 个赞

该组件除了应用水印外,不执行任何修改或压缩。

Discourse 会先预处理图像(使用 squoosh 库)-> 应用水印 → 上传图像到服务器。它的工作原理就是这样。

6 个赞


第一次打开帖子并编辑时,您无法添加水印,需要先发布帖子,然后点击“编辑帖子”并上传图片才能添加水印。
使用的主题是 FKB Pro - Social theme - #375 by MihirR

2 个赞

您的意思是,如果您第一次打开/编辑现有帖子并上传图片,则没有水印。这正确吗?您每次都能重现它吗?您在浏览器的控制台中看到任何错误吗?

如果我理解正确,您期望在编辑帖子时,一个已上传的现有图片(在此 TC 安装之前)会带有水印(或者有手动添加水印的方法)。它不是这样工作的。您需要上传图片才能应用水印。

提供一个手动为选定图片添加水印的按钮可能是一个功能。这对您有用吗?

新帖子创建后上传的图片没有水印,但发帖后进入帖子点击编辑上传的图片却有水印。

对于发帖按钮,我使用的是 Compose Center - #13

请问您能快速制作一个视频吗?这样有助于我们看到和理解正在发生的事情。

1 个赞

3 个赞

感谢您的耐心等待!我找到了问题所在。现在应该已经修复了! :+1:

3 个赞

安装此组件时出现此错误

发生错误:创建上传资产时出错:worker_photon_wasm。原始文件名抱歉,您尝试上传的文件未获授权(授权扩展名:jpg、jpeg、png、woff、woff2、svg、eot、ttf、otf、gif、js、dwg)。

1 个赞

这很奇怪。您的 Discourse 版本是什么?

您可以尝试在允许列表中添加 wasm 扩展名,但在我的本地和两个生产安装中,它在没有任何更改的情况下都能正常工作。:thinking:

1 个赞

我将提供一些反馈,我不知道发生了什么,但似乎中国用户上传的图片没有水印。

但我使用的是一个新创建的、已开启无痕模式的账户,而且它正在工作,所以我不知道问题出在哪里。

有时有效,有时无效。

下载的图片是.jpeg .png格式。但就像视频中的图片一样,我复制图片并上传它,它就有水印,所以我不知道问题出在哪里。

感谢您的反馈!

对您来说,无论您怎么尝试,它总是能正常工作,对吧?

您能否请一些您的用户在出现问题时检查浏览器的控制台,并将他们看到的任何错误消息复制给您?另外,他们是否使用的是移动设备(Android、iPhone 等)——如果他们能解释他们具体做了什么,也许能有所帮助,我们将不胜感激。

如果之后您自己能够为图片添加水印,那看起来就不像是图片本身的问题了。剩下的要么是像之前那样代码中的错误,要么是水印处理过程中的错误。不幸的是,无论我怎么做都无法重现它。

我将着手更新该组件,以确保任何错误都能被捕获并显示给用户。

您好,感谢您制作此组件。
当我尝试上传水印照片时,出现此错误。我尝试了 JPEG 和 Webp,但仍然无效。

我的 Discourse 论坛是最新的

1 个赞

您好 @LaptechInfo

这很奇怪。此时,TC 应该什么都不做。这是标准的上传设置。
您能否查看浏览器的控制台,看看是否有任何错误消息?

您能否提供一张失败的图片,以便我也能在我的这边进行测试?

1 个赞

您好,我尝试了许多随机图片,但没有一张起作用。
我不是程序员,不懂任何计算机语言。
请尝试这张图片,我已尽力。
laptechinfo webp.zip (558 Bytes)
watermark.zip (257.7 KB)

@Arkshine

1 个赞

谢谢!您能也展示一下您的 Console 内容吗?就在旁边的标签页。我想这可能会有帮助。

编辑:我想我能重现它了,让我看看,很快给您回复!

控制台选项卡


@Arkshine

@LaptechInfo 谢谢!昨天有一个来自 PR 的 Discourse bug。我创建了一个主题:https://meta.discourse.org/t/cant-upload-image-in-settings/352213。 :+1:

3 个赞