Warning: Undefined array key "night" in /www/wwwroot/dhaomu.com/wp-content/themes/b2/header.php on line 18

图片在线转换SVG单页HTML源码

简介:

图片转换SVG网页HTML源码,只是把位图包装成了矢量图的格式。直接把位图的每个像素塞进去svg,这样生成的放大后会样糊。

图片:

图片在线转换SVG单页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>

温馨提示:
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:duhaomu@163.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

给TA赞赏
共{{data.count}}人
人已赞赏
未整理

白面鸮·音律联觉

2023-9-30 0:00:00

未整理

最新抖音去水印PHP源码 非第三方接口

2023-10-2 0:00:00

0 条回复 A文章作者 M管理员

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914
----《》
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索