上传图片时加水印

发布于 2024-08-08 14:40:47 字数 175 浏览 8 评论 0原文

我正在创建一个网站,需要为网站图库中的图像添加水印。我更喜欢在图像上传到应用程序(通过其 Web 界面)时以编程方式添加水印,而不是在上传之前手动添加水印。

有没有任何简单的方法(也许是图像库?)可以让我做到这一点?

我正在使用 Grails 构建站点,因此 Groovy 或 Java 解决方案会很棒。

I'm creating a website which requires the images in the site's Gallery to be watermarked. I'd prefer the watermark to get added programatically when the image gets uploaded to the application (via it's web interface) than to manually add it before we do the upload.

Are there any simple ways (perhaps an image library?) that will allow me to do this?

I'm building the site in Grails, so a Groovy or Java solution would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

清旖 2024-08-15 14:40:47

我想这就是你想要的代码......

BufferedImage source = ...;
BufferedImage watermark = ...;
Graphics2D g = source.createGraphics();
g.drawImage(watermark, x, y, null);
g.dispose();

This is the code you want I think...

BufferedImage source = ...;
BufferedImage watermark = ...;
Graphics2D g = source.createGraphics();
g.drawImage(watermark, x, y, null);
g.dispose();
无声静候 2024-08-15 14:40:47

我不确定版权和您的流程是否允许,但另一种建议是在显示图像时呈现水印,而不是在上传时更改图像。这将允许您更改水印并访问原始图像。

I'm not sure if copyright and your process allows but an alternative suggestion is to render the watermark when the images are displayed rather than altering the image on upload. This would allow you to change the watermark and have access to the raw image.

勿忘心安 2024-08-15 14:40:47

我一直在开发一个 Grails 应用程序,该应用程序可以进行大量图像处理,我们选择调用 ImageMagick。 Grails 有一个图像工具插件,可能适合简单的水印,但是我们需要 IM 提供的额外功能。

Groovy 的 Process 附加功能使得调用 IM 然后解析 err/out 流变得非常容易。如果我有时间我会发布一个 IM 插件,但我不后悔!

干杯

I've been working on an Grails application that does a lot of image manipulation and we chose to call out to ImageMagick. There is an Image Tools plugin for Grails which might be suitable for simple watermarking, however we needed the extra power that IM provides.

Groovy's Process additions make it pretty easy to call out to IM and then parse the err/out streams. If I had time I'd release an IM plugin, but I don't sorry!

cheers

Lee

探春 2024-08-15 14:40:47

创建一个缓冲图像。将上传的图片绘制到BufferedImage中,然后将水印绘制到BufferedImage中。

Create a BufferedImage. Draw the uploaded image to the BufferedImage and then draw the watermark to the BufferedImage.

冷月断魂刀 2024-08-15 14:40:47

如果您使用grails,我认为添加水印或调整图像大小以使用burningimage插件的最简单方法
https://grails.org/plugin/burning-image

它非常易于使用且有详细记录。在这里找到文档:
https://code.google.com/p/burningimage/

前往您简单的水印必须执行以下操作

burningImageService.doWith('path/to/my/file', 'path/to/output/dir')
               .execute {
                   it.watermark('path/to/watermark', ['top':10, 'bottom': 10])
                }

If you are using grails, I think the easiest way to add a watermark or resize the image to use the burningimage plugin
https://grails.org/plugin/burning-image

Its very easy to use and well documented. Find the documentation here:
https://code.google.com/p/burningimage/

To the the watermark you simple have to do the following

burningImageService.doWith('path/to/my/file', 'path/to/output/dir')
               .execute {
                   it.watermark('path/to/watermark', ['top':10, 'bottom': 10])
                }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文