
第1步,先下载软件然后安装打开,点击软件界面左边最上面的【图片水印】功能,然后点击【添加文件】按钮,将需要添加水印的图片导入到软件中,支持批量导入和批量处理。
第2步,图片导入成功后在软件右下方进行设置:水印类型选择“图片水印”,选择单个或者多个;然后上传图片logo,设置logo的缩放比例/透明度/旋转角度;最后设置水印的位置、水印密度(数量)等。
第3步,在上方可以实时预览到添加水印后的样子,方便及时调整,点开还可以放大预览。没问题后就可以点击【开始转换】按钮启动软件了。
第4步,随后软件会自动打开一个文件夹,所有添加水印后的图片会被保存到这里。可以看到所有图片都成功添加了logo水印。
在使用php编程的时候, 很多时候需要对上传的图片加水印,来确定图片版权和出处. 但是,一般情况下加水印的位置是图片的右下角, 但是,不同图片的色阶不同,有时候我们 图片的水印和图片本身色阶相同,就会造成水印不明显.下面这段代码可以实现自动识别图片的色阶,更加色阶差来添加图片的水印,这样可以避免水印和图片色阶一样的弊端.
<?php
function add_wm($nmw_water, $src_file, $output_file, $x, $y) {
if(file_exists($output_file))
return
$w1 = MagickGetImageWidth($nmw_water)
$h1 = MagickGetImageHeight($nmw_water)
$nmw =NewMagickWand()
MagickReadImage($nmw, $src_file)
// 默认的加水印位置调整
$lt_w = 50
$lt_h = 50
if($x == 0){
$w = MagickGetImageWidth($nmw)
$h = MagickGetImageHeight($nmw)
$x = $w
$y = $h
}else{
// 根据具体情况调整
$lt_w = 30
$lt_h = 40
}
MagickCompositeImage($nmw, $nmw_water, MW_OverCompositeOp, $x - $w1 - $lt_w, $y - $h1 - $lt_h)
MagickWriteImage($nmw, $output_file)
DestroyMagickWand($nmw)
}
// 还是groovy的eachFileRecurse好用啊
function add_wm_recurse($nmw_water, $to_dir, $output_dir, $arr) {
$dp = dir($to_dir)
while($file=$dp->read()){
if($file != '.' &&$file != '..'){
if(is_dir($to_dir . '/' . $file)){
mkdir($output_dir . '/' . $file)
add_wm_recurse($nmw_water, $to_dir . '/' . $file, $output_dir . '/' . $file, $arr)
}else{
if(!array_key_exists($to_dir . '/' . $file, $arr)){
continue
}
$sub_arr = $arr[$to_dir . '/' . $file]
if($sub_arr){
$x = intval($sub_arr[0])
$y = intval($sub_arr[1])
add_wm($nmw_water, $to_dir . '/' . $file, $output_dir . '/' . $file, $x, $y)
}
}
}
}
$dp->close()
}
$to_dir = './resized'
$output_dir = './output'
// 这个是我用java的ImageIO遍历图片像素获取的符合裤子颜色的区域的坐标array(posX, posY)
$arr = array(
array(50, 50)
)
$water = './water.png'
$nmw_water =NewMagickWand()
MagickReadImage($nmw_water, $water)
add_wm_recurse($nmw_water, $to_dir, $output_dir, $arr)
DestroyMagickWand($nmw_water)
?>
补充:
PHP图像处理模块 MagickWand用法
MagickWand 是一个PHP的模块,用来访问 ImageMagick 的图像处理库。下面是一个使用 MagicWand 的代码片段:
$magick_wand=NewMagickWand()
MagickReadImage($magick_wand,'rose.jpg')
$drawing_wand=NewDrawingWand()
DrawSetFont($drawing_wand,"/usr/share/fonts/bitstream-vera/Vera.ttf")
DrawSetFontSize($drawing_wand,20)
DrawSetGravity($drawing_wand,MW_CenterGravity)
$pixel_wand=NewPixelWand()
PixelSetColor($pixel_wand,"white")
DrawSetFillColor($drawing_wand,$pixel_wand)
if (MagickAnnotateImage($magick_wand,$drawing_wand,0,0,0,"Rose") != 0)
{
MagickEchoImageBlob( $magick_wand )
}
else
{
echo MagickGetExceptionString($magick_wand)
}
?>
安装方法:
1. 下载 php_magickwand_q16_st.dll for 5.2.x
2. 将其放在PHP的扩展目录
3. 在php.ini文件总增加 extension=php_magickwand_q16_st.dll
4. 重新启动apache
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)