找回密码
  注册[Register]
查看: 154|回复: 2

[其他] 【HTML】图片转换SVG

[复制链接]
发表于 2023-10-16 09:52 | 显示全部楼层 |阅读模式
禁止求评分、诱导评分、互刷评分、互刷悬赏值,违规者封号处理。
禁止发布推广、邀请码、邀请链接、二维码或者有利益相关的任何推广行为。
所有非原创软件请发布在【精品软件区】,发帖必须按照本版块版规格式发帖。

[HTML] 纯文本查看 复制代码
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>SVG图片生成器</title>
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      background-color: #f7f7f7;
      font-family: Arial, sans-serif;
    }
     
    .container {
      text-align: center;
      padding: 20px;
      background-color: #fff;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
 
    h1 {
      margin-top: 0;
    }
 
    input[type="file"] {
      margin-bottom: 10px;
      display: none;
    }
 
    label {
      display: inline-block;
      padding: 10px 20px;
      background-color: #007bff;
      color: #fff;
      cursor: pointer;
    }
 
    .avatar {
      margin-top: 10px;
      max-width: 100%;
      height: auto;
    }
 
    .download-button {
      margin-top: 10px;
      display: none;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>SVG图片生成器</h1>
    <label for="upload">选择图片</label>
    <input id="upload" type="file" required accept="image/gif, image/jpeg, image/png">
    <img class="avatar" src="" alt="Avatar Preview">
    <a class="download-button" href="#" download="noavatar.svg">下载 SVG</a>
  </div>
 
<script>
document.getElementById('upload').addEventListener('change', function() {
  var file = this.files[0];
  if (file) {
    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.addEventListener('load', function() {
      var dataURL = this.result;
      var svgCode = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="120" height="120"><image xlink:href="'+dataURL+'" height="120" width="120"/></svg>';
      var blob = new Blob([svgCode], {type: 'image/svg+xml'});
      var url = URL.createObjectURL(blob);
      document.querySelector('.avatar').src = url;
      document.querySelector('.download-button').style.display = 'inline-block';
      document.querySelector('.download-button').href = url;
    });
  }
});
</script>
</body>
</html>

如何回报帮助你解决问题的坛友,一个好办法就是给对方加【热心值】和【牛币】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2023-10-16 10:08 | 显示全部楼层
666666666666
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【热心值】和【牛币】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 有用 没用

使用道具 举报

发表于 2023-10-16 10:27 | 显示全部楼层
666666
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【热心值】和【牛币】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 有用 没用

使用道具 举报

您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

RSS订阅|手机版|小黑屋|大牛论坛 |我的广告

GMT+8, 2024-5-5 04:50 , Processed in 0.035200 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表