Advertisement
Guest User

Untitled

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