Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. local ImageHtmlFormat = [[
  2. <html>
  3. <head>
  4. <style>
  5. .container {
  6. width: 100%%;
  7. height: 100%%;
  8. margin: auto;
  9. overflow: hidden;
  10. }
  11. .container > img {
  12. position: relative;
  13. }
  14. body {
  15. margin: 0;
  16. }
  17. img {
  18. filter: brightness(50%);
  19. }
  20. </style>
  21.  
  22. <script type="text/javascript">
  23. function onLoad()
  24. {
  25. var img = document.getElementById("img");
  26.  
  27. var iw = img.width;
  28. var ih = img.height;
  29.  
  30. var fw = window.innerWidth;
  31. var fh = window.innerHeight;
  32.  
  33. var mode = %d; // mode 0 - FILL, mode 1 - FIT
  34.  
  35. var scale = Math.max(fw / iw, fh / ih);
  36.  
  37. if (mode != 0)
  38. {
  39. scale = Math.min(fw / iw, fh / ih);
  40. }
  41.  
  42. var sw = scale * iw;
  43. var sh = scale * ih;
  44.  
  45. img.style.width = sw + "px";
  46. img.style.height = sh + "px";
  47. img.style.left = ((fw - sw) / 2) + "px";
  48. img.style.top = ((fh - sh) / 2) + "px";
  49.  
  50. }
  51. </script>
  52. </head>
  53.  
  54. <body>
  55. <div class="container">
  56. <img id="img" src="%s" onLoad="onLoad();"/>
  57. </div>
  58. </body>
  59. </html>]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement