我目前正在使用this Paperclip::Processor通过imagemagick的复合命令为图像添加水印。
它允许我注入一个预先制作的单个文件作为水印,它存在于我的公共文件中。
但是,我正在尝试弄清楚是否有可能对其进行修改,以动态生成包含模型属性的水印。例如,水印包括摄影师的姓名,或拍摄时使用的相机型号。
Getty最近有了changed their watermark to do just this -它非常聪明,我很想知道他们是如何做到的。
在此之前,非常感谢您。我并不期望人们确切地知道如何做到这一点,但任何想法或一般原则都会受到赞赏。
发布于 2013-03-04 18:02:40
谢谢你的帮助比灵顿。实际上,我想出了一种方法,在回形针缩略图过程中将convert_options添加到图像中。因此,在图像模型上,a是图像:
has_attached_file :image,
processors: [:thumbnail],
styles: {
wide: {
geometry: "1120x",
convert_options: ->(a) { "-quality 92 -font Arial -pointsize 72 -gravity center gradient: -alpha on -channel rgba -fill 'rgba(255,255,255,0.3)' -opaque 'rgba(20,20,20,1)' -draw \"text 0, 340 #{a.picusername}\" -pointsize 30 -draw \"text 0, 390 'license copy here'\"
"}
}这将在图像上写入具有各种放置和样式细节的a.picusername。你可以找到更多这样的here。
最后要注意的是,如果您使用诸如simpleform之类的方法将属性添加到图像模型中,则在将图像本身添加到数据库时,将应用上述处理指令。因此,在图像附加之后添加的任何模型属性(从字面上看,在图像附加下面的表单输入中)将不会被识别,因为它们还不存在。
发布于 2013-03-01 20:50:06
是的,这可以用Imagemagick完成;我已经用php和一个批处理脚本完成了。不过,我不知道如何将这个批处理脚本转换为ruby-on-rails。
您可以获取EXIF数据中包含的大多数值,并在类似下面的代码中使用它们。
:: Do not display the code while running
@ECHO OFF
:: Select the F number from the EXIF data and set the FNumber variable
FOR /F %%x IN ('identify -ping -format "%%[EXIF:FNumber]" %1') DO SET FNumber=%%x
:: Set the FNumber1 variable to the F number value
:: Image Magick returns the F number in the format of 700/100 or 40/10
FOR /F %%x IN ('convert xc: -ping -format "%%[fx:%FNumber%]" info:') DO SET FNumber1=%%x
:: Set the value of the shutter variable to the shutter speed
:: Select the shutter speed from the EXIF data
:: Image Magick returns the shutter speed in the format of 810/100
FOR /F %%x IN ('identify -ping -format "%%[EXIF:ShutterSpeedValue]" %1') DO SET shutter=%%x
:: Format the speed to 8.1 and set the speed variable
FOR /F %%x IN ('convert xc: -ping -format "%%[fx:%shutter%]" info:') DO SET speed=%%x
:: Calculate the speed in seconds using the power of 2
:: and save it in the shutterspeed variable
FOR /F %%x IN ('convert xc: -ping -format "%%[fx:floor((pow(2,%speed%)))]" info:') ^
DO SET shutterspeed=%%x
:: Add the F number and shutter speed to the image
:: and save as exif_OriginalImageName
convert %INPUTFILE% ^
-pointsize 16 -fill black -gravity northwest ^
-annotate +10+5 "Aperture: F%FNumber1% Shutter speed: 1/%shutterspeed% sec" "%~p1EXIF_%~n1.jpg" https://stackoverflow.com/questions/15156090
复制相似问题