loadimg.html 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>画板</title>
  8. <style>
  9. .canvas {
  10. border: 1px solid rgb(170, 170, 170);
  11. cursor: pointer;
  12. }
  13. .mgTop {
  14. margin-top: 30px;
  15. text-align: center;
  16. }
  17. </style>
  18. <script src="https://cdn.bootcss.com/fabric.js/2.2.3/fabric.min.js"></script>
  19. </head>
  20. <body style="padding-left: 10px;text-align:center;">
  21. <h1>图片加载</h1>
  22. <div class="mgTop">
  23. <canvas id="freeCanvas" class="canvas"></canvas>
  24. </div>
  25. <script>
  26. var canvas = new fabric.Canvas("freeCanvas", {
  27. isDrawingMode: false,
  28. selection: false,
  29. width: 1000,
  30. height: 600
  31. });
  32. fabric.Image.fromURL('../image/tools-28.png', function (img) {
  33. img.scaleToHeight(224 / 2, false); //缩放图片高度
  34. img.scaleToWidth(168 / 2, false); //缩放图片宽度
  35. canvas.add(img);
  36. });
  37. </script>
  38. </body>
  39. </html>