2017-10-10 90 views
1

我在R中使用magick库我想在一些图片上添加水印。水印在R中加入

我用image_annotate函数如下。

img <- image_read("C:\\Users\\Maydin\\Desktop\\manzara.png") 
image_annotate(img, "my watermark", gravity = "northwest", location = "+200+275", 
       degrees = -30, size =50, font = NULL, color = "transparent", 
       strokecolor = "gray90", boxcolor = NULL) 

最后,输出看起来像这样;

enter image description here

不过,我想拥有的是这样的事情,

enter image description here

那是可行的,在Rmagick

+0

你能提供输入照片吗? –

+0

@ Hack-R我把它上传到这个链接:https://imgur.com/0qgo1ML – maydin

回答

4

例如,这

download.file("https://i.stack.imgur.com/7X5To.png", tf<-tempfile(fileext = ".png"), mode="wb") 
library(magick) 
img <- image_read(tf) 
library(extrafont) 
truetype_path <- paste0("@", subset(fonttable(), FullName=="Matura MT Script Capitals", fontfile)[1,]) 
image_annotate(img, "my watermark", gravity = "northwest", location = "+70+220", 
       degrees = -30, size = 80, font = truetype_path, color = "#FFFFFF66", 
       strokecolor = NULL, boxcolor = NULL) 

给出了这样的形象:

enter image description here

即,选择一个漂亮的字体如可能马图拉MT脚本首都,告诉image_annotate哪里上找到它您的硬盘驱动器,调整color参数中的不透明度 - 等瞧。字体不会放下阴影或显示浮雕,但也许你可以通过绘制文本两次来模拟这个文字,黑色阴影与另一个轻微偏移。

+0

它不是我的目标相同,但绝对比我的工作更好:)谢谢你...我尝试了它,并且它运作良好!但是,我不明白你所说的不透明度调整。你是否想说要从调色板中选择一种颜色,就像这个链接所述:http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf?或者是否存在我不知道的不透明度调整方式? – maydin

+1

@maydin颜色代码是RGBA(红色绿色蓝色阿尔法),每一个范围从0到255(以十六进制表示的00到FF)。因此'color =“#FFFFFF11”,strokecolor =“#FFFFFF22”'会为您填充颜色提供高透明度的白色,并减少笔触颜色的透明度。 – lukeA

+0

好的。最后的数字是为了设置不透明度..我不知道这一点。谢谢。 – maydin