简体   繁体   English

如何在果园CMS中添加自动图像水印?

[英]How to add auto image watermark in orchard CMS?

I use Orchard cms. 我用Orchard cms。 I want when images uploaded, the images get watermark automatically. 我想在上传图片时,图片会自动获得水印。 How can I do this? 我怎样才能做到这一点?

To add watermark automatically, you have to add a OnPublished handler for ImagePart as following: 要自动添加水印,您必须为ImagePart添加OnPublished处理程序,如下所示:

OnPublished<ImagePart>((context, part) => {
    var mediaPart = part.As<MediaPart>();
    // Here you can add watermark code
});

If you want to add the watermark on the original uploaded image, you have to call it from the handler directly, but if you want to use media processing module mechanism (Which will keep the original image as is, and create a new one with filters applied and save it in _Profiles folder), then you can add a new implementation for IImageFilterProvider to add a new filter for Orchard media processing pipeline. 如果要在原始上传的图像上添加水印,则必须直接从处理程序中调用它,但是如果要使用媒体处理模块机制(这将保持原始图像不变,并使用过滤器创建一个新图像应用并将其保存在_Profiles文件夹中),然后您可以为IImageFilterProvider添加新实现,为Orchard媒体处理管道添加新的过滤器。

Finally, I recommend you to use ImageResizer.Plugins.Watermark plugin to achieve this, because Orchard already use ImageResizer component as default image processing framework. 最后,我建议你使用ImageResizer.Plugins.Watermark插件来实现这一点,因为Orchard已经使用ImageResizer组件作为默认的图像处理框架。

Update: Please refer to this link for complete implementation, or this repo for source code. 更新:请参阅此链接以获取完整实施,或请参阅此repo获取源代码。

This should be possible by providing a custom implementation of IImageFilterProvider . 这应该可以通过提供IImageFilterProvider的自定义实现来IImageFilterProvider Search for this interface in the solution, you will find a ResizeFilter and FormatFilter in the Orchard.MediaProcessing module as an example. 在解决方案中搜索此接口,您将在Orchard.MediaProcessing模块中找到ResizeFilterFormatFilter作为示例。

Also, there are some articles like http://www.davidhayden.me/blog/developing-custom-image-filters-in-orchard-cms . 此外,还有一些文章,如http://www.davidhayden.me/blog/developing-custom-image-filters-in-orchard-cms

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM