HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<noscript>
<div class="ns pt5"><span style="font-size:24px">This demo needs JavaScript</span></div>
</noscript>
<div class="all_wrapper">
<div class="ib">
<p class="ms"><span id="note" data-title="Use local file" class="sbg">Use local file</span></p>
<p class="pm0 ms">
<input type="file" id="inp" class="ms">
</p>
</div>
<div class="ib">
<p class="ms"><span data-title="Use external URL" id="notee" class="sbg">Use external URL</span></p>
<p class="pm0 ms">
<input type="url" id="inp_url" placeholder="image url" class="ms green">
<input type="button" value="submit" class="ms" id="submit_url" disabled>
</p>
</div>
<div class="inner_holder">
<canvas class="canvas_styling" id="imageCanvas"></canvas>
</div>
<div class="inner_holder">
<p id="st" class="ms"><small>Click below to select</small></p>
<textarea rows="1" id="output_url" class="URI_textarea ms" onclick="this.select();document.getElementById('st').innerHTML=this.getAttribute('data-text')?'...':'Selected..';" onblur="document.getElementById('st').innerHTML=!this.getAttribute('data-text')?'Click below to select':this.getAttribute('data-text');"
wrap="off" readonly></textarea>
<h3 class="sub_title ms" id="sub_title">Your base-64 encoded image!</h3>
</div>
</div>
<div class="picture-container">
<img onclick="this.src=document.getElementById('output_url').value" id="picture" class="picture" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxISEhUSEhMQFRUQFRUSEBUVFQ8PFRAVFRUWFhUVFRUYHSggGBolGxUVITEhJSkrLi4uFx8zODMsNygtLisBCgoKDg0OGhAQFy0dHx0tLS0tLSstLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS4tLS0tLS0tLS0tLS0tLS0tLSstLf/AABEIAKgBLAMBIgACEQEDEQH/xAAcAAABBQEBAQAAAA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cW+fNFxDpLsutrtfZZrfWtkqJX/AKXNuW+VgADT0UQTzrXbQK135aC1poHU9D8/sqpxALhqwC9QQfwSC/ZIh173rrX2Sc8jnfry/ummljstDtfLQf7TzTMcALsmzQugfRAbkSEh2S7xGxkjiyhFG06U4OrXzH+VWizZTm571r8NdkDTCG/nsmEnI7eqEHEjc10NWEg7TnfXp9UDDd50/6UbQy4dSmJvr5aIAcmgQTf4enRIN8yfrSYEc1CQgbgO/PqgKCiNzho53oDpp86+FLlO3Whjb4qOZwDtxsF1LSKtvh6lum65HtrZfGSSfCd/VWYvuKs32M5lwTsKSS1GEkkVEpApEtwi5Gbo31Q422U80lpibByvzH7KACekSMIEQpGlk8ICEQkQgCFJJ0iEANSScBJAHo/fef42lHPyIPx2P1SSWI6FjjLegFn1TUDyb/KE6SAHaBuWih5IgLSNA2yarn8k6SBjtpu2l/n4JopQLy5eh53fXokkgdB4nkdAT+6XEeim6U8iKHkE6SRIaOc1fXTlYQXvBOw132H1TJIQiURA0FgHkKI+KJJlcPeBAoEADbY6c06SGFIFIAW5XPks671qp4aV7LomiK8QDr67pJIsKQzZKN1euxTZ9dkkkDE5wuq5WeaJpv/AGSSSBAg9v5vVRfIAela8gPh1SSTFYnS+ZPy/sud7ZAOaxwB8LiPSwnSU8f3Iryu4s5JOmSWowCKVpkkwJNND1USmSQA4CkCkkgBkySSYDJFJJIBBMU6SAP/2Q==">
</div>
<a id="try-it" href="#">
<img class="button-try" src="http://remmache.fr/map/button.svg">
</a>
body {
background-color: #eee;
}
* {
line-height: normal !important;
}
body,
.ms {
font-family: consolas, monaco, menlo, courier, monospace;
text-align: center;
}
.pm0 {
padding: 0;
margin: 0;
}
.pt5 {
padding-top: 5px;
}
.URI_textarea {
font-size: 14px;
padding: 10px;
margin: 0;
border: 0;
box-shadow: 1px 1px 2px #555 inset;
background-color: #ddd;
color: darkgreen;
resize: none;
}
.canvas_styling {
opacity: 0;
transition: opacity .5s;
display: inline-block;
border-radius: 8px;
padding: 20px;
background-color: #888;
box-shadow: 0 0 20px #555 inset;
}
.inner_holder {
box-sizing: border-box;
overflow: auto;
border-radius: 4px;
display:none;
}
.URI_textarea,
.canvas_holder,
.all_wrapper,
.ib,
input {
box-sizing: border-box;
}
.all_wrapper,
.URI_textarea {
width: 100%;
}
.all_wrapper p,
.sub_title,
.all_wrapper,
.ns {
text-align: center;
}
#inp:hover {
cursor: pointer;
}
.sub_title {
color: darkgreen;
}
input[type="button"] {
background-color: #ddd;
}
.sbg,
input[type="button"],
#inp_url {
border-radius: 4px;
padding: 10px 20px;
}
#inp::-webkit-file-upload-button {
border-radius: 4px;
padding: 10px 20px;
font-family: consolas, monaco, menlo, courier, monospace;
border: 1px solid #555;
}
input[type="button"],
#inp_url {
border: 1px solid #555;
}
#inp_url,
#submit_url {
display: block;
width: 100%;
margin: 0 auto;
}
#submit_url {
margin-top: 10px;
}
input[type="button"]:hover {
background-color: #888;
color: #fff;
cursor: pointer;
}
#inp::-webkit-file-upload-button:hover {
background-color: #888;
color: #fff;
cursor: pointer;
}
input[type="button"]:disabled {
cursor: not-allowed;
background-color: #ccc;
color: #777;
}
input[type="button"]:focus {
outline-color: #333;
}
#inp::-webkit-file-upload-button:focus {
outline-color: #333;
}
.sbg {
background-color: #333;
color: #fff;
padding: 10px 20px;
}
.all_wrapper {
padding: 10px 0;
}
.ib {
display: inline-block;
vertical-align: top;
margin-bottom: 20px;
}
.green {
color: darkgreen;
}
.all_wrapper,
.inner_holder {
display: none;
}
@media (max-width:640px) {
.ib {
display: block;
margin: 0;
width: 100%;
}
.ib:nth-child(2) {
margin-top: 5px;
margin-bottom: 20px;
}
#inp_url,
#submit_url {
width: 200px;
max-width: 100%;
}
.pt5 {
padding: 0;
}
}
/* Base */
body {
background: url(https://jaysalvat.github.io/jquery.facedetection/assets/background.jpg);
}
a {
color: inherit;
text-decoration: none;
}
.logo {
position: relative;
display: block;
margin: 20px auto;
width: 400px;
}
.button-try {
position: relative;
display: block;
margin: -80px auto 20px;
width: 250px;
}
.button-download {
display: block;
margin: 50px auto;
width: 160px;
text-transform: uppercase;
padding: 20px;
border: 3px solid #fff;
border-radius: 10px;
text-align: center;
color: #fff;
font: bold 0.8em Arial, sans-serif;
}
.button-visit:hover {
background: rgba(255, 255, 255, 0.1);
}
.picture-container {
position: relative;
width: 600px;
height: 100%;
margin: 20px auto;
border: 10px solid #fff;
background: #000;
box-shadow: 0 5px 5px #000;
}
.picture {
display: block;
width: 100%;
height: auto;
}
.face {
position: absolute;
border: 2px solid #FFF;
padding:-40px;
}
#imageCanvas{
display:none;
}
(function (d) {
"use strict";
//Elements/objects global variables
var inp, out, note, notee, st, sut, iu, su, ch, aw, canvas, c2d;
//Get element(s) (by Id or Class)
function q(a) {
var buff;
if (!(/^\./.test(a))) {
if (d.getElementById(a)) {
buff = d.getElementById(a);
} else {
buff = d.querySelector(a);
}
} else {
buff = Array.prototype.slice.call(d.querySelectorAll(a));
}
return buff;
}
//IMG TESTER
function imt(a) { // test the local file's tail-strings (allowed image format/extension)
return (/jpe?g|gif|png|bmp|webp|svg/i).test(a);
}
//ELEMENTS/OBJECTS VARS INIT
inp = q("inp"); //input file
out = q("output_url"); //the base64 URI output text
note = q("note"); //local file notification
notee = q("notee"); //external url notification
st = q("st"); //the "select"
sut = q("sub_title"); //the bottom notification
iu = q("inp_url"); //external url input
su = q("submit_url"); //external url button
ch = q(".inner_holder"); //inner holders (plural)
aw = q(".all_wrapper")[0]; //outer holder
canvas = q("imageCanvas"); //the canvas
//[canvas] related
c2d = canvas.getContext("2d");
//CHECK HTML5 COMPATIBILITY
(function () {
aw.style.display = "block";
if ((typeof canvas !== "object") && (typeof FileReader !== "function")) {
aw.innerHTML = "<span style='font-size:24px'>Your browser doesn't support <strong>HTML5</strong> built-in API.</span>";
//all functions below will have no triggers, because the "all_wrapper" content is changed to be just that "span" above.
}
}());
//COMMON HANDLERS
function loadThis(a) {
canvas.width = a.width;
canvas.height = a.height;
c2d.drawImage(a, 0, 0);
}
function showElms() {
ch.forEach(function (v) {
v.style.display = "block";
});
canvas.style.opacity = 1;
}
function hideElms() {
ch.forEach(function (v) {
v.style.display = "none";
});
out.removeAttribute("style");
out.value = "";
inp.value = "";
canvas.removeAttribute("style");
st.removeAttribute("style");
sut.removeAttribute("style");
c2d.clearRect(0, 0, canvas.width, canvas.height);
note.innerHTML = note.getAttribute("data-title");
notee.innerHTML = notee.getAttribute("data-title");
if (out.getAttribute("data-text")) {
out.removeAttribute("data-text");
}
su.disabled = 1;
}
//EXTERNAL URL CHECKER
function check_img_URL(a, b) {
var protocol = /^https?:\/\//.test(a.value),
btn = q(b);
//RESET LOCAL INPUT AND OUTPUT
if (inp.value.length) {
inp.value = "";
}
note.innerHTML = note.getAttribute("data-title");
a.removeAttribute("style");
//hideElms();
//CHECK URL STARTS HERE
if (protocol && a.value.length > 20 &&
a.value.match(/\//g).length > 2 &&
a.value.match(/\./g).length > 1 &&
imt(a.value)) {
btn.disabled = 0;
} else if (a.value.length === 0) {
hideElms();
} else {
a.style.color = "brown";
btn.disabled = 1;
}
}
//EXTERNAL URL HANDLER (BUTTON CLICK)
function handle_img_URL() {
var img_url = iu.value,
new_img = d.createElement("img"),
word;
new_img.src = img_url;
new_img.addEventListener("load", function () {
if (new_img.complete) {
try { //umm...
loadThis(new_img); //draw the image to [canvas].
out.value = c2d.getImageData(0, 0, new_img.width, new_img.height).data; //get URI.
notee.innerHTML = "Done!"; //not really.
} catch (error) { //this'd certainly happen.
if (error) {
word = error.toString();
word = word.substring(0, word.indexOf(":"));
out.setAttribute("data-text", "<span style='color:red'>" + word + "</span>");
out.value = error.message;
out.style.color = "purple";
if (window.innerWidth > 1024) {
out.style.overflowX = "hidden";
}
st.innerHTML = "<span style='color:red'>" + word + "</span>";
sut.style.display = "none";
notee.innerHTML = "<span style='color:violet'>" + word + "</span>";
}
}
su.disabled = 1;
showElms();
}
}, 0);
}
//LOCAL FILE HANDLER
function handleImage(e) { // http://stackoverflow.com/a/10906961
//the "e" is the "change" event object from the input[type='file'].
//you can console.log(e) to find out the what's in it.
var reader = new FileReader(),
theFile = e.target.files[0]; //the file object being loaded.
try {
if (imt(theFile.type)) { //test if it has the allowed format, using imt() function - declared above.
//to get the file size, use [size] key
//as in: theFile.size (using the variable "theFile") <- it's in Bytes (number).
//to get the file name, use [name] key
//example: theFile.name <- returns string
reader.readAsDataURL(theFile);
//wait for the image to load.
reader.addEventListener("load", function (ev) {
//the "ev" parameter is the "reader" variable load event object.
//you can console.log(ev) to find out what's in it.
var img = d.createElement("img"); //create [img] object.
//the conversion product is right here [ev.target.result]
img.src = ev.target.result; //the [img] source -> base64 URI strings.
//And then listen to the load event of that [img] object.
img.addEventListener("load", function () {
loadThis(img); //draw that [img] to the [canvas].
}, 0);
out.value = img.src; //base64 URI strings.
$('.face').remove();
$('#picture').attr('src', document.getElementById('output_url').value);
note.innerHTML = "Done!"; //notification.
st.innerHTML = "Click below to select"; //notification.
}, 0);
} else {
window.alert("Only jpg, jpeg, gif, png, bmp, webp, and svg");
hideElms();
return;
}
} catch (error) {
if (error) { // This happens when we cancel the file window opener.
hideElms();
return;
}
}
out.removeAttribute("style");
showElms();
}
//EVENT LISTENERS
su.onclick = handle_img_URL;
inp.onclick = function () {
hideElms();
iu.value = "";
};
inp.onchange = handleImage;
iu.oninput = function () {
check_img_URL(iu, "submit_url");
};
iu.onclick = function () {
iu.select();
};
}(document));
//This demo uses the built-in input[type="file"] display with subtle CSS override.
//This is a neat snippet by Chris Coyier for styling that exciting HTML5 element: https://css-tricks.com/snippets/css/custom-file-input-styling-webkitblink/
$('#try-it').click(function (e) {
e.preventDefault();
$('.face').remove();
$('#picture').faceDetection({
complete: function (faces) {
for (var i = 0; i < faces.length; i++) {
$('<div>', {
'class':'face',
'css': {
'position': 'absolute',
'left': ((faces[i].x * faces[i].scaleX ) - 15)+ 'px',
'top': ((faces[i].y * faces[i].scaleY) - 25) + 'px',
'width': ((faces[i].width * faces[i].scaleX) + 30) + 'px',
'height': ((faces[i].height * faces[i].scaleY) + 40) + 'px',
'bottom' : '-20px'
}
})
.insertAfter(this);
}
},
error:function (code, message) {
alert('Error: ' + message);
}
});
});
Also see: Tab Triggers