text_to_image.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>distribution</title>
  6. <style>
  7. .novel-to__picBox {
  8. width: 1000px;
  9. margin: 0 auto;
  10. background: #fff;
  11. padding: 26px;
  12. }
  13. .canvas-content {
  14. user-select: none;
  15. background: #fff;
  16. }
  17. .pic-title {
  18. font-size: 18px;
  19. }
  20. .item-group {
  21. display: flex;
  22. justify-content: flex-start;
  23. align-items: center;
  24. margin: 20px 0;
  25. }
  26. .item-label {
  27. width: 120px;
  28. font-size: 16px;
  29. }
  30. .content-input {
  31. width: 400px;
  32. }
  33. .button {
  34. background-color: #39a4ff;
  35. color: #fff;
  36. padding: 5px 10px;
  37. font-weight: 900
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <div id="app">
  43. <div class="novel-to__picBox">
  44. <div class="pic-title">文字转图片</div>
  45. <div class="cavans-box">
  46. <div class="item-group">
  47. <div class="item-label">文字内容</div>
  48. <div class="item-content">
  49. <div id="summernote"></div>
  50. </div>
  51. </div>
  52. <div class="item-group">
  53. <div class="item-label"></div>
  54. <div class="item-content">
  55. <div class="button" @click="build">生成</div>
  56. </div>
  57. </div>
  58. </div>
  59. <div class="preview-box">
  60. <div class="pic-title">预览:</div>
  61. <p class="canvas-content" v-html="content"></p>
  62. </div>
  63. <a id="download" href="#" style="display:none"></a>
  64. </div>
  65. </div>
  66. <script src="https://cdn.jsdelivr.net/npm/vue"></script>
  67. <!-- include libraries(jQuery, bootstrap) -->
  68. <link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
  69. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
  70. <script src="https://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
  71. <!-- include summernote css/js -->
  72. <link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote.css" rel="stylesheet">
  73. <script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote.js"></script>
  74. <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.5.0-beta4/html2canvas.js"></script>
  75. </body>
  76. <script>
  77. var app = new Vue({
  78. el: '#app',
  79. data() {
  80. return {
  81. fontSize: 16,
  82. content: "",
  83. bold: "normal",
  84. isPreview: false
  85. };
  86. },
  87. created() {
  88. $(document).ready(function () {
  89. $("#summernote").summernote({
  90. height: 300,
  91. minHeight: null,
  92. maxHeight: null,
  93. focus: true
  94. });
  95. $("#summernote").summernote("code", "");
  96. });
  97. },
  98. mounted() {
  99. let that = this;
  100. $("#summernote").summernote({
  101. height: 300,
  102. callbacks: {
  103. onChange: function (contents) {
  104. that.content = contents;
  105. console.log(that.content);
  106. }
  107. }
  108. });
  109. },
  110. methods: {
  111. build() {
  112. html2canvas(document.querySelector(".canvas-content")).then(canvas => {
  113. let img = canvas.toDataURL("image/jpeg");
  114. let downLoad = document.querySelector("#download");
  115. downLoad.setAttribute("download", "章节内容");
  116. downLoad.setAttribute("href", img);
  117. downLoad.click();
  118. });
  119. }
  120. }
  121. })
  122. </script>
  123. </html>