Note that there are some explanatory texts on larger screens.

plurals
  1. POfit image to screen properly in javascript
    primarykey
    data
    text
    <p>I need to resize image from its natural size to fit the screen the same way as Chrome does with opened images in it, I wrote a <code>rescale(</code>) function for this purpose (below).</p> <p>It works mostly fine but for big landscape-oriented images (example where both width and height both exceed screen after resizing with my function <a href="http://imageontime.com/upload/big/2013/07/20/51ea60b522bba.jpg" rel="nofollow">http://imageontime.com/upload/big/2013/07/20/51ea60b522bba.jpg</a> ) fullscreened image still exceeds screen by few lines at height (and rarely at width), so i wanted to ask if there is a better rescale javascript function out there or if here are any chromium source adepts who could look into chromiums source code to get the image resizing function from it so I could port it into javascript?</p> <p>Here's the code:</p> <pre><code>function setautow() { img.style.width = 'auto'; img.style.removeProperty("height"); if (document.documentElement.clientHeight == 0) // Firefox again... { img.height = window.innerHeight; } else { img.height = document.documentElement.clientHeight; } } function setautoh() { img.style.height = 'auto'; img.style.removeProperty("width"); if (document.documentElement.clientWidth == 0) // FF { img.width = window.innerWidth; } else { img.width = document.documentElement.clientWidth; } } function shrink(a) { if (a) { if (img.width != document.documentElement.clientWidth) { setautoh(); } } else { if (img.height != document.documentElement.clientHeight) { setautow(); } } } var rescaled = false; function rescale() { if (rescaled) { rescaled = false; img.height = img.naturalHeight; img.width = img.naturalWidth; img.style.removeProperty("height"); img.style.removeProperty("width"); } else { rescaled = true; if (img.naturalWidth &gt; img.naturalHeight) { setautoh(); setTimeout(function () { shrink(true); }, 0); } else { setautow(); setTimeout(function () { shrink(false); }, 0); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload