選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

162 行
4.2 KiB

  1. <html>
  2. <head>
  3. <title><%= title %></title>
  4. <link rel="icon" type="image/png" href="../favicon.png">
  5. <style>
  6. body {
  7. font-family: 'Segoe UI', Arial;
  8. background-color: #aaa;
  9. padding: 0;
  10. margin: 0;
  11. }
  12. .bg-0 {
  13. background-image: url("https://github.com/benc-uk/icon-collection/raw/master/_tools/background.png")
  14. }
  15. .bg-1 {
  16. background-color: #333;
  17. }
  18. .bg-2 {
  19. background-color: #fff;
  20. }
  21. .imgbox img {
  22. width: 10.5rem;
  23. height: 10.5rem;
  24. object-fit: contain;
  25. cursor: pointer;
  26. }
  27. .imgbox {
  28. margin: 0.6rem;
  29. padding: 0.5rem;
  30. text-align: center;
  31. width: 12rem;
  32. height: 12rem;
  33. background-color: #e0e0e0;
  34. }
  35. h1 {
  36. font-size: 2.6rem;
  37. }
  38. .find, .find input {
  39. font-size: 1.5rem;
  40. }
  41. .top {
  42. position: -webkit-sticky;
  43. position: sticky;
  44. top: 0;
  45. background-color: #aaa;
  46. padding: 1rem;
  47. box-shadow: 0px 5px 18px 3px rgba(0,0,0,0.59);
  48. }
  49. .top button {
  50. float: right;
  51. position: relative;
  52. top: -2rem;
  53. font-size: 1.5rem;
  54. }
  55. .pngbox {
  56. position: absolute;
  57. top: 2rem;
  58. right: 1rem;
  59. font-size: 1.5rem;
  60. }
  61. input[type="checkbox"] {
  62. width: 1.6em;
  63. height: 1.6em;
  64. }
  65. .label {
  66. height: 2.5em;
  67. line-height: 1em;
  68. overflow: hidden;
  69. font-size: 0.9rem;
  70. }
  71. .grid {
  72. display: flex;
  73. flex-wrap: wrap;
  74. width: 100%;
  75. }
  76. h1 {
  77. display:inline;
  78. }
  79. .home {
  80. font-size: 3rem;
  81. text-decoration: none
  82. }
  83. </style>
  84. </head>
  85. <body>
  86. <div class="top">
  87. <a href=".." class="home">&#129093;</a> &nbsp; <h1><%= title %></h1>
  88. <br/><br/>
  89. <span class="find">Finder: <input onkeyup="search()" id="finder">&nbsp; Icons: <span id="count">...</span><br> </span>
  90. <div class="pngbox"><input type="checkbox" id="pngcheck"><label for="pngcheck">Download as PNG</label></div>
  91. <button onclick="toggleBg()">Change Background</button>
  92. </div>
  93. <div class="grid">
  94. <% for(let imgFile of images) { %>
  95. <div id="<%= imgFile.toLowerCase() %>" class="imgbox"><img src="<%= imgFile %>" class="bg-0" onclick="download('<%= imgFile %>', this)"/><div class="label"><%= imgFile %></div></div>
  96. <% } %>
  97. </div>
  98. <script>
  99. var bgSetting = 0;
  100. function toggleBg() {
  101. bgSetting++
  102. if(bgSetting > 2) bgSetting = 0;
  103. for(let img of document.getElementsByTagName("img")) {
  104. img.className = `bg-${bgSetting}`;
  105. }
  106. }
  107. function search() {
  108. let query = document.getElementById('finder').value.trim().toLowerCase()
  109. if(query.length <= 0) {
  110. for(let imgbox of document.getElementsByClassName("imgbox")) {
  111. imgbox.style.display = "inline-block"
  112. }
  113. }
  114. for(let imgbox of document.getElementsByClassName("imgbox")) {
  115. imgbox.style.display = "inline-block"
  116. if(!imgbox.id.includes(query)) {
  117. imgbox.style.display = "none"
  118. }
  119. }
  120. }
  121. function download(f, e) {
  122. if(document.getElementById("pngcheck").checked) {
  123. var data = getBase64Image(e);
  124. let a = document.createElement('a')
  125. a.href = "data:application/octet-stream;base64," + data
  126. a.download = f.replace('.svg', '.png')
  127. a.click()
  128. } else {
  129. let a = document.createElement('a')
  130. a.href = f
  131. a.download = f
  132. a.click()
  133. }
  134. }
  135. // Actual magic
  136. function getBase64Image(img) {
  137. var canvas = document.createElement("canvas");
  138. canvas.width = img.naturalWidth;
  139. canvas.height = img.naturalHeight;
  140. console.log(canvas.width , canvas.height)
  141. var ctx = canvas.getContext("2d");
  142. ctx.drawImage(img, 0, 0);
  143. var dataURL = canvas.toDataURL("image/png");
  144. return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
  145. }
  146. function updateCount() {
  147. document.querySelector('#count').innerHTML = ''+document.querySelectorAll(".imgbox").length
  148. }
  149. updateCount()
  150. </script>
  151. </body>
  152. </html>