gpt4 book ai didi

ruby-on-rails - 动态图像水印——将模型属性注入(inject)水印

转载 作者:行者123 更新时间:2023-12-04 05:08:49 25 4
gpt4 key购买 nike

我目前正在使用 this Paperclip::Processor使用 imagemagick 的复合命令为图像添加水印。

它允许我注入(inject)一个预制的单个文件作为水印,它存在于我的公共(public)文件中。

但是,我正在尝试确定是否可以对其进行修改以动态生成包含模型属性的水印。例如,水印包括摄影师的姓名,或拍摄它的相机型号。

盖蒂最近有changed their watermark to do just this - 它非常聪明,我很想知道他们是如何做到的。

提前谢谢了。我不希望人们确切地知道如何做到这一点,但任何想法或一般原则将不胜感激。

最佳答案

是的,它可以用 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"

关于ruby-on-rails - 动态图像水印——将模型属性注入(inject)水印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15156090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com