Initializing
Liveweave
Web
expand_more
home
Home
data_object
CSS Explorer
arrow_outward
Palette
Color Explorer
arrow_outward
Polyline
Graphics Editor
arrow_outward
outbox_alt
Generative AI
arrow_outward
frame_source
Python Playground
New
arrow_outward
build
Tools
expand_more
restart_alt
Load "Hello Weaver!"
post_add
Generate Lorem ipsum...
code
Format HTML
code_blocks
Format CSS
data_object
Format JavaScript
library_add
Library
expand_more
A
Algolia JS
Animate CSS
Apex Charts JS
B
Bulma CSS
Bootstrap
C
Chart JS
Chartist
Create JS
D
D3
Dojo
F
Foundation
Fullpage JS
G
Granim JS
Google Charts
H
Halfmoon
J
jQuery
M
Materialize
Moment JS
Masonry JS
Milligram CSS
P
Pure CSS
Primer CSS
Popper JS
Pattern CSS
Picnic CSS
R
React JS
Raphael JS
Raisin CSS
S
Semantic UI
Skeleton CSS
Spectre CSS
Tachyons CSS
T
Tailwind
Three JS
U
UI Kit
Vis JS
W
Water CSS
download
Download
expand_more
developer_mode
Download as HTML
folder_zip
Download as .ZIP
cloud_upload
Save
account_circle
Login
settings
Settings
expand_more
14
px
Live mode
Night mode
Line number
Mini map
Word wrap
sync_alt
Reset Settings
smart_display
Run
<!DOCTYPE html> <html> <head> <title>HTML5, CSS3 and JavaScript demo</title> </head> <body> <!-- Start your code here --> <img id="your-image" src="//liveweave.com/about/images/5.png"/> <!-- End your code here --> </body> </html>
body { background: yellow; } img { width: 300px; }
window.onload = function(){ // Write JavaScript here // get the image, the image MUST BE LOCAL var img = document.getElementById("your-image"); var height = img.offsetHeight; var width = img.offsetWidth; // create and customize the canvas var canvas = document.createElement("canvas"); canvas.width = width; canvas.height = height; // get the context var ctx = canvas.getContext("2d"); // draw the image into the canvas ctx.drawImage(img, 0, 0); // get the image data object var image = ctx.getImageData(0, 0, width, height); // get the image data values var imageData = image.data, length = imageData.length; // every fourth value is Alpha channel // lets make bottom right triangle transparent for(var i=3; i<length; i+=4){ // for calculations we need to know current pixel position on image // we define pixel left, top, right and bottom relative to the image rectangle // first index is 1, first pixel for width=4: left=1, right=4 var pixel = (i+1)/4; var left = (pixel-1)%width+1; var top = Math.floor(pixel/width); var right = width-left+1; var bottom = height-top+1; // it is easy now to find pixel in bottom right rectangle: if( (right+bottom)<=100 ) { // make this pixel transparent console.log( 'left: ' + left + ' right: ' + right + ' top: ' + top + ' bottom: ' + bottom); imageData[i] = 0; } } // after the manipulation, reset the data image.data = imageData; // and put the imagedata back to the canvas ctx.putImageData(image, 0, 0); img.src = canvas.toDataURL(); };