()
| 225 | |
| 226 | //read and accept user input image |
| 227 | function readSourceImage(){ |
| 228 | |
| 229 | //remove any existing images |
| 230 | while (imageContainer.firstChild) { |
| 231 | imageContainer.removeChild(imageContainer.firstChild); |
| 232 | } |
| 233 | |
| 234 | if(playAnimationToggle == true){ |
| 235 | clearInterval(animationInterval); |
| 236 | playAnimationToggle = false; |
| 237 | } |
| 238 | |
| 239 | //read image file |
| 240 | var file = imageInput.files[0]; |
| 241 | var reader = new FileReader(); |
| 242 | reader.onload = (event) => { |
| 243 | var imageData = event.target.result; |
| 244 | var image = new Image(); |
| 245 | image.src = imageData; |
| 246 | image.onload = () => { |
| 247 | |
| 248 | actualWidth = image.width; |
| 249 | actualHeight = image.height; |
| 250 | |
| 251 | //image scaling |
| 252 | if(actualWidth > maxImageWidth){ |
| 253 | scaledWidth = maxImageWidth; |
| 254 | widthScalingRatio = scaledWidth / actualWidth; |
| 255 | scaledHeight = actualHeight * widthScalingRatio; |
| 256 | } else{ |
| 257 | scaledWidth = actualWidth; |
| 258 | widthScalingRatio = 1; |
| 259 | scaledHeight = actualHeight; |
| 260 | } |
| 261 | |
| 262 | animation.width = scaledWidth; |
| 263 | animation.height = scaledHeight; |
| 264 | |
| 265 | //resize the src variable of the original image |
| 266 | var newCanvas = document.createElement('canvas'); |
| 267 | newCanvas.width = Math.floor(scaledWidth/2)*2; //video encoder doesn't accept odd numbers |
| 268 | newCanvas.height = Math.floor(scaledHeight/8)*8; //video encoder wants a multiple of 8 |
| 269 | var ctx = newCanvas.getContext('2d'); |
| 270 | ctx.drawImage(image, 0, 0, scaledWidth, scaledHeight); |
| 271 | |
| 272 | var resizedImgSrc = newCanvas.toDataURL(); |
| 273 | |
| 274 | //draw the resized image onto the page |
| 275 | originalImg = document.createElement('img'); |
| 276 | originalImg.setAttribute("id", "originalImg"); |
| 277 | originalImg.src = resizedImgSrc; |
| 278 | originalImg.width = scaledWidth; |
| 279 | originalImg.height = scaledHeight; |
| 280 | imageContainer.appendChild(originalImg); |
| 281 | |
| 282 | setTimeout(createAnimation(),1000); |
| 283 | animation.scrollIntoView({ behavior: "smooth" }); |
| 284 |
nothing calls this directly
no test coverage detected