Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, I've fixed it. Man was that hard! Mainly because you forgot to set the imageCanvas' canvas height. It also didn't help that the image has a white border. I spent a hell of a lot of time trying to figure out where the padding was coming from. </p> <p>So to start, for the case of the <a href="http://jsfiddle.net/254ck/4/">fiddle</a>, in function <code>doBlending()</code>, set <code>imageCanvas.canvas.height = height;</code></p> <p>Then the calculations in <code>crop()</code> need to cover 2 possibilities. Is the image being scaled for height and truncated on the left or scaled for width and truncated on the bottom? I'm not going to write both for you, but here's the one for the case where it is scaled for height:</p> <pre><code>function crop(imageObj, imageCanvas, colorCanvas) { // Assumes bg image is scaled for hight var scale = imageObj.height / window.innerHeight; var targetHeight = imageCanvas.canvas.height; var targetWidth = window.innerWidth; imageCanvas.drawImage(imageObj, 0, 0, targetWidth * scale, targetHeight * scale, 0, 0, targetWidth, targetHeight); } </code></pre> <p>I really have no idea where you came up with the scaling factors in your example. The image is going to be scaled by multiplying both the x and y dimensions by some scale factor. That's how you preserve the aspect ratio. The scale factor will be the larger of the one to make the height of the image match the height of the window and the one to make the width of the image match the width of the window.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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