fix: [crawled screenshot] fix img error

This commit is contained in:
Terrtia 2018-09-18 16:58:49 +02:00
parent 5b31b6e853
commit 912f2352ab
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
2 changed files with 18 additions and 16 deletions

View file

@ -166,16 +166,12 @@
ctx.webkitImageSmoothingEnabled = false; ctx.webkitImageSmoothingEnabled = false;
ctx.imageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false;
/// wait until image is actually available
img.onload = pixelate; img.onload = pixelate;
img.addEventListener("error", img_error);
var draw_img = false; var draw_img = false;
img.onError = "img.onerror=null;img.src='{{ url_for('static', filename='image/AIL.png') }}';"
/// some image, we are not struck with CORS restrictions as we
/// do not use pixel buffer to pixelate, so any image will do
img.src = "{{ url_for('showsavedpastes.screenshot', filename=screenshot) }}"; img.src = "{{ url_for('showsavedpastes.screenshot', filename=screenshot) }}";
/// MAIN function
function pixelate() { function pixelate() {
/// use slider value /// use slider value
@ -195,14 +191,19 @@
/// draw original image to the scaled size /// draw original image to the scaled size
ctx.drawImage(img, 0, 0, w, h); ctx.drawImage(img, 0, 0, w, h);
/// then draw that scaled image thumb back to fill canvas /// pixelated
/// As smoothing is off the result will be pixelated
ctx.drawImage(canvas, 0, 0, w, h, 0, 0, canvas.width, canvas.height); ctx.drawImage(canvas, 0, 0, w, h, 0, 0, canvas.width, canvas.height);
} }
/// event listeneners for slider and button
blocks.addEventListener('change', pixelate, false); blocks.addEventListener('change', pixelate, false);
function img_error() {
img.onerror=null;
img.src="{{ url_for('static', filename='image/AIL.png') }}";
blocks.value = 50;
pixelate;
}
</script> </script>
</body> </body>

View file

@ -596,16 +596,12 @@ var ctx = canvas.getContext('2d'), img = new Image();
ctx.webkitImageSmoothingEnabled = false; ctx.webkitImageSmoothingEnabled = false;
ctx.imageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false;
/// wait until image is actually available
img.onload = pixelate; img.onload = pixelate;
img.addEventListener("error", img_error);
var draw_img = false; var draw_img = false;
img.onError = "img.onerror=null;img.src='{{ url_for('static', filename='image/AIL.png') }}';"
/// some image, we are not struck with CORS restrictions as we
/// do not use pixel buffer to pixelate, so any image will do
img.src = "{{ url_for('showsavedpastes.screenshot', filename=crawler_metadata['screenshot']) }}"; img.src = "{{ url_for('showsavedpastes.screenshot', filename=crawler_metadata['screenshot']) }}";
/// MAIN function
function pixelate() { function pixelate() {
/// use slider value /// use slider value
@ -625,13 +621,18 @@ function pixelate() {
/// draw original image to the scaled size /// draw original image to the scaled size
ctx.drawImage(img, 0, 0, w, h); ctx.drawImage(img, 0, 0, w, h);
/// then draw that scaled image thumb back to fill canvas /// pixelated
/// As smoothing is off the result will be pixelated
ctx.drawImage(canvas, 0, 0, w, h, 0, 0, canvas.width, canvas.height); ctx.drawImage(canvas, 0, 0, w, h, 0, 0, canvas.width, canvas.height);
} }
/// event listeneners for slider and button function img_error() {
img.onerror=null;
img.src="{{ url_for('static', filename='image/AIL.png') }}";
blocks.value = 50;
pixelate;
}
blocks.addEventListener('change', pixelate, false); blocks.addEventListener('change', pixelate, false);
</script> </script>