纯HTML代码实现给图片增加水印并下载保存到本地

在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>图片水印打码工具-宋佳乐博客</title>
    <style>
        #container {
            max-width: 500px;
            margin: 30px auto;
        }

        h1 { margin: 0 }
        p, article { margin: 0 0 20px 0 }
        article { font-size: 14px; color: #777 }

        label { color: blue; font-size: 17px }
        p label { color: black; display: inline-block; width: 50px; font-size: 15px }
        p { font-size: 15px; line-height: 30px }

        input#text { width: 100%; box-sizing: border-box; font-size: 16px; margin-bottom: 10px }
        input[type=range] { width: 200px; height: 18px; vertical-align: text-bottom }

        canvas { box-sizing: border-box; width: 100%; border: 1px dashed #AAA; cursor: pointer }
    </style>
</head>
    <div id="container">
        <h1>图片水印打码工具丨宋佳乐博客丨www.songjiale.com</h1>
        <article>安全地为你的图片加水印,无任何网络请求,特别适合各种敏感证件(身份证,驾照,护照等)。<a href="http://www.songjiale.com" target="_blank">更多精品</a></article>
        <label for="image">第一步:先选择一张本地图片</label>
        <p><input type="file" id="image" autocomplete="off"></p>

        
        <label for="text">第二步:输入需要打水印的文字</label>
        <p><input type="text" id="text" placeholder="请输入文字" autocomplete="off" maxlength="30">
        
        <label for="color">颜色</label>
        <input type="color" id="color" pattern="#[0-9A-Fa-f]{6}" autocomplete="off" value="#0000FF"><br>
        
        <label for="alpha">透明度</label>
        <input type="range" id="alpha" min="0" max="1" step="0.05" autocomplete="off" value="0.15"><br>
        
        <label for="space">间隔</label>
        <input type="range" id="space" min="1" max="8" step="0.2" autocomplete="off" value="4"><br>
        
        <label for="size">字号</label>
        <input type="range" id="size" min="0.5" max="3" step="0.05" autocomplete="off" value="1">
        </p>
        
        <label for="text">第三步:点击图片下载</label>
        <p id="graph"></p>
    </div>
    <script src="http://960416654.free3v.work/AI/tpsy/build/script.js"></script>

<div class="bdsharebuttonbox"><A class=bds_more href="#" tangram_guid="TANGRAM_2830" data-cmd="more"></A><A class=bds_qzone title=分享到QQ空间 href="#" data-cmd="qzone"></A><A class=bds_tsina title=分享到新浪微博 href="#" data-cmd="tsina"></A><A class=bds_tqq title=分享到腾讯微博 href="#" data-cmd="tqq"></A><A class=bds_renren title=分享到人人网 href="#" data-cmd="renren"></A><A class=bds_weixin title=分享到微信 href="#" data-cmd="weixin"></A></div>
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"1","bdMiniList":["mshare","qzone","tsina","bdysc","weixin","tqq","tqf","tieba","bdhome","sqq","taobao","hi","mogujie","diandian","huaban","duitang","hx","fx","youdao","sdo","qingbiji","people","xinhua","mail","kanshou","isohu","yaolan","wealink","ty","iguba","fbook","twi","linkedin","copy","print"],"bdPic":"","bdStyle":"0","bdSize":"32"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
</ul>
</div>

</html>

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
你可以使用Java的ImageIO类和Graphics2D类来编辑图片并添加水印文字,然后使用File类来保存到指定路径。以下是一个简单的示例代码: ```java import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class AddWatermark { public static void main(String[] args) { try { // 读取原始图片 BufferedImage originalImage = ImageIO.read(new File("original.jpg")); // 创建一个新的图片,大小和原始图片一样 BufferedImage newImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_RGB); // 在新图片上绘制原始图片 Graphics2D graphics = newImage.createGraphics(); graphics.drawImage(originalImage, 0, 0, null); // 添加水印文字 Font font = new Font("Arial", Font.BOLD, 30); graphics.setFont(font); graphics.setColor(Color.WHITE); graphics.drawString("Watermark Text", 10, 50); // 保存图片 File output = new File("output.jpg"); ImageIO.write(newImage, "jpg", output); System.out.println("水印添加成功!"); } catch (IOException e) { System.out.println("水印添加失败!"); e.printStackTrace(); } } } ``` 在上面的示例代码中,我们首先使用ImageIO类读取原始图片,然后创建一个新的同样大小的图片,使用Graphics2D类在新图片上绘制原始图片,并添加水印文字。最后使用ImageIO类保存图片到指定路径。注意修改文件名和路径以适应你的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宋佳乐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值