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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<header class="container">
<h1>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-0.5 -0.5 114 17"><title>LinePrint.svg</title><g stroke="#000" fill="none" stroke-linecap="square"><path d="M-.5 0h114"/><path stroke-width=".96" d="M-.5 1h114"/><path stroke-width=".92" d="M-.5 2h15m2 0h40m2 0h14m2 0h39"/><path d="M14.5 2h2m40 0h2m14 0h2m-73 1h6m7 0h2m21 0h7m12 0h2m14 0h2m-73 1h6m30 0h8m27 0h2m-71 1h2m7 0h4m4 0h6m4 0h4m4 0h2m3 0h2m1 0h3m1 0h3m1 0h4m4 0h6m2 0h7m9 0h6m1 0h4m1 0h4m2 0h7M3.5 6h2m7 0h4m4 0h7m2 0h6m3 0h2m3 0h2m1 0h7m1 0h4m4 0h7m1 0h7m8 0h2m3 0h2m1 0h4m1 0h4m2 0h7M3.5 7h2m9 0h2m5 0h2m2 0h2m1 0h2m4 0h2m2 0h7m2 0h3m1 0h2m3 0h2m5 0h2m2 0h2m3 0h2m11 0h4m5 0h2m3 0h2m2 0h2m3 0h2M3.5 8h2m3 0h2m4 0h2m5 0h2m2 0h2m1 0h8m2 0h6m3 0h2m7 0h2m5 0h2m2 0h2m3 0h2m12 0h5m4 0h2m1 0h2m3 0h2m3 0h2M3.5 9h2m3 0h2m4 0h2m5 0h2m2 0h2m1 0h2m8 0h2m7 0h2m7 0h2m5 0h2m2 0h2m3 0h2m2 0h2m2 0h3m5 0h4m3 0h2m1 0h2m3 0h2m3 0h2m-109 1h9m1 0h8m1 0h4m1 0h3m1 0h7m1 0h5m3 0h6m2 0h8m1 0h4m1 0h3m2 0h6m2 0h3m2 0h2m3 0h2m4 0h3m4 0h7m-109 1h9m1 0h8m1 0h4m1 0h3m2 0h5m2 0h5m3 0h6m2 0h8m1 0h4m1 0h3m3 0h4m3 0h3m2 0h6m5 0h2m6 0h6m-2 1h2m-6 1h6m-6 1h5" stroke="none"/><path stroke-width=".88" d="M-.5 3h2m6 0h7m2 0h21m7 0h12m2 0h14m2 0h39"/><path stroke-width=".84" d="M-.5 4h2m6 0h30m8 0h27m2 0h39"/><path stroke-width=".8" d="M-.5 5h4m2 0h7m4 0h4m6 0h4m4 0h4m2 0h3m2 0h1m3 0h1m3 0h1m4 0h4m6 0h2m7 0h9m6 0h1m4 0h1m4 0h2m7 0h2"/><path stroke-width=".75" d="M-.5 6h4m2 0h7m4 0h4m7 0h2m6 0h3m2 0h3m2 0h1m7 0h1m4 0h4m7 0h1m7 0h8m2 0h3m2 0h1m4 0h1m4 0h2m7 0h2"/><path stroke-width=".7" d="M-.5 7h4m2 0h9m2 0h5m2 0h2m2 0h1m2 0h4m2 0h2m7 0h2m3 0h1m2 0h3m2 0h5m2 0h2m2 0h3m2 0h11m4 0h5m2 0h3m2 0h2m2 0h3m2 0h3"/><path stroke-width=".65" d="M-.5 8h4m2 0h3m2 0h4m2 0h5m2 0h2m2 0h1m8 0h2m6 0h3m2 0h7m2 0h5m2 0h2m2 0h3m2 0h12m5 0h4m2 0h1m2 0h3m2 0h3m2 0h3"/><path stroke-width=".6" d="M-.5 9h4m2 0h3m2 0h4m2 0h5m2 0h2m2 0h1m2 0h8m2 0h7m2 0h7m2 0h5m2 0h2m2 0h3m2 0h2m2 0h2m3 0h5m4 0h3m2 0h1m2 0h3m2 0h3m2 0h3"/><path stroke-width=".53" d="M-.5 10h2m9 0h1m8 0h1m4 0h1m3 0h1m7 0h1m5 0h3m6 0h2m8 0h1m4 0h1m3 0h2m6 0h2m3 0h2m2 0h3m2 0h4m3 0h4m7 0h3"/><path stroke-width=".47" d="M-.5 11h2m9 0h1m8 0h1m4 0h1m3 0h2m5 0h2m5 0h3m6 0h2m8 0h1m4 0h1m3 0h3m4 0h3m3 0h2m6 0h5m2 0h6m6 0h3"/><path stroke-width=".4" d="M-.5 12h109m2 0h3"/><path stroke-width=".34" d="M-.5 13h105m6 0h3"/><path stroke-width=".28" d="M-.5 14h105m5 0h4"/><path stroke-width=".22" d="M-.5 15h114"/><path stroke-width=".17" d="M-.5 16h114"/></g></svg>
</h1>
<p>Miss the wonderful whirr, perforated pages and lined printing of old printers? Recreate that magic (minus the whirr and paper) with fully scalable SVGs. Upload an image and watch the magic!</p>
<p><em>Need more SVG? Try <a href="https://codepen.io/shshaw/pen/doLavv" target="_top">HalfTone.svg</a> and <a href="https://codepen.io/shshaw/pen/XbxvNj" target="_top">Pixels.svg</a>.</em></p>
<!--<p class="note"></p>-->
<div class="choices">
<div class="file">
Drag & Drop files or
<input type="file" id="upload" multiple="multiple" accept=".jpg,.jpeg,.png,.gif,.svg" />
</div>
<button id="test">Try a test image: <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAwICAgJCAwJCQwRCwoLERUPDAwPFRgTExUTExgXEhQUFBQSFxcbHB4cGxckJCcnJCQ1MzMzNTs7Ozs7Ozs7OzsBDQsLDQ4NEA4OEBQODw4UFBARERAUHRQUFRQUHSUaFxcXFxolICMeHh4jICgoJSUoKDIyMDIyOzs7Ozs7Ozs7O//CABEIAOMAlgMBIgACEQEDEQH/xAAbAAABBQEBAAAAAAAAAAAAAAAEAQIDBQYAB//aAAgBAQAAAACwJY+COR0Uq8xrkkWAwl/DRydJLEk0C86IY8xzFhRMvWWmkJFe6QaEywVixL5wflas/wBhWR8cIx5k0bexGyOzPl9TufRXI8QensbXi4fKPVZabKeemeh3Zpwlbhr6FNGN5/qzQBMD2qtrnWV1Dij3jRjr7DW2fneATU2ZejrQMRcNcLXx+t5fRYXMpZlPOErkNVs3VN7uMvma1lyZE5K9ktoQdHkhLqMisFOsWxSCz2U4bB6d/oNquJpRLI7R1mYMN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DemxhBBIIojoeQh5WeQcicL4oABUZTqM2/wDYTwkNspqYiI5Af3SNHbUX6MNv2jcIiHKzNffSqj4OGNrvtf3jCjR5Vzw8fDKFzoBuOsfizmJUVfr95+MGtqKPvL+lv9GPiWTlvL+m+0OITvrDryvnmIBHQyzLPtjkfb//2Q==" id="testImage" /></button>
<button id="clear">Clear Output</button>
</div>
</header>
<div id="output"></div>
<div id="filedrag">Drop images to convert here.</div>
<div class="container">
<h2>Tips</h2>
<p>Works best with high-contrast images where the dimensions are relatively small. Images larger than 512x512 are scaled down.</p>
<p>After conversion, run the output through <a href="https://jakearchibald.github.io/svgomg/">SVGOMG</a> for even smaller file sizes.</p>
</div>
@accent: @gray-dark;
@accent-light: lighten(@gray-dark,20%);//#FF7777;
@gray-dark: #535050;
@gray: #ddd;
@gray-light: #eaeaea;
@gray-lighter: #f5f5f5;
body {
background: @gray-lighter;
font-family: 'Courier', 'Courier New', monospace;
padding: 1em;
padding-bottom: 2em;
margin: auto;
font-size: 14px;
line-height: 1.4;
}
.container { margin: 1em auto; max-width: 40em; }
.container:first-child { margin-top: 0; }
.note { background: #ffee77; font-size: 0.8em; text-align: center; padding: 0.5em; }
h1, h2 { display: block; margin: 0 auto 0.5em; }
h2 { font-size: 1.4em; color: @accent; }
h2 svg { height: 21px; width: auto; margin: 0; }
h2 svg path { stroke: currentColor; }
p { margin: 0 auto 1em; }
a {
color: @accent;
transition: color 250ms ease-in-out;
&:hover,
&:focus { color: @accent-light; }
}
img { vertical-align: middle; }
button {
background: #ddd;
border: none;
appearance: none;
cursor: pointer;
}
button, .file {
padding: 0.75em;
}
svg, label, input[type=file] {
display: block;
margin: auto;
text-align: center;
}
label small { display: block; }
svg { max-width: 100%; }
.choices {
background: #eaeaea;
display: flex;
align-items: stretch;
}
.choices button {
background: transparent;
font-size: 0.8em;
border-left: solid 3px #aaa;
}
.choices > * { flex: 1 1 auto; }
.file { overflow: hidden; flex-basis: 40%; }
#test img { max-width: 30px; }
#output { margin: auto auto 2em; text-align: center; }
.output {
display: flex;
width: 100%;
margin: 0;
justify-content: space-between;
align-items: stretch;
padding: 2em 0;
border-bottom: solid 3px @gray;
}
.output > a {
display: block;
width: 50%;
}
.output svg {
width: 100%;
height: auto;
margin: 0 auto;
}
.output__details {
width: 50%;
display: flex;
flex-direction: column;
}
.output__raw {
display: block;
background: #eaeaea;
white-space: pre-wrap;
padding: 0.5em;
font-size: 0.75em;
max-height: 20em;
overflow: auto;
text-align: left;
}
.download,
.output__size {
display: inline-block;
text-align: center;
margin: 1em auto 0;
padding: 0.25em 0.5em;
font-size: 0.8em;
}
.download { background-color: #f05555; color: #FFF; }
#filedrag { display: none; }
#filedrag.dragenter {
position: fixed;
top: 0; right: 0; bottom: 0; left: 0;
margin: auto;
background: #ff5555;
background: rgba(255,200,200,0.8);
text-align: center;
display: block;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
z-index: 999;
}
console.clear();
console.time = console.time || function(){};
console.timeEnd = console.timeEnd || function(){};
// Adjust this value at your own peril!
var maxSize = 512;
(function(){
"use strict";
function each(obj,fn) {
var length = obj.length,
likeArray = ( length === 0 || ( length > 0 && (length - 1) in obj ) ),
i = 0;
if ( likeArray ) {
for ( ; i < length; i++ ) { if ( fn.call( obj[ i ], i, obj[ i ] ) === false ) { break; } }
} else {
for (i in obj) { if ( fn.call( obj[ i ], i, obj[ i ] ) === false ) { break; } }
}
}
function convertImage(img){
"use strict";
function each(obj,fn) {
var length = obj.length,
likeArray = ( length === 0 || ( length > 0 && (length - 1) in obj ) ),
i = 0;
if ( likeArray ) {
for ( ; i < length; i++ ) { if ( fn.call( obj[ i ], i, obj[ i ] ) === false ) { break; } }
} else {
for (i in obj) { if ( fn.call( obj[ i ], i, obj[ i ] ) === false ) { break; } }
}
}
function makePathData(x,y,w) {
w = w ? 'h'+w : 'z';
return ('M'+x+' '+y+w);
}
function getBrightness(img) {
var lums = {},
data = img.data,
len = data.length,
w = img.width,
h = img.height,
x = 0,
y = 0,
i = 0,
brightest = 0,
lum;
for (; i < len; i+= 4) {
if ( data[i+3] > 0 ) {
lum = data[i+3] - (data[i] + data[i+1] + data[i+2])/3;
lum = ( lum / 256 ).toFixed(2);
lums[lum] = lums[lum] || [];
x = (i / 4) % w;
y = Math.floor((i / 4) / w);
lums[lum].push([x,y]);
//output+='<circle cx="'+x+'" cy="'+y+'" r="'+lum/255 +'" />\n';
}
}
return lums;
}
function makeCirclePath(lum,data) {
return '<path stroke-width="'+lum+'" d="'+data+'" />\n';
}
function lumsToPaths(lums){
var output = "";
/* each(lums,function(lum,coords){
var paths = [];
each(coords,function(i,coord){
paths.push(makePathData(coord[0],coord[1]));
});
output += makeCirclePath(lum,paths.join(''));
});*/
// Loop through each color to build paths
each(lums,function(color,values){
if ( color === false ) { return; }
var paths = [];
var curPath;
var w = 1;
// Loops through each color's pixels to optimize paths
each(values,function(){
if ( curPath && this[1] === curPath[1] && this[0] === (curPath[0] + w) ) {
w++;
} else {
if ( curPath ) {
paths.push(makePathData(curPath[0],curPath[1],w));
w = 1;
}
curPath = this;
}
});
paths.push(makePathData(curPath[0],curPath[1],w)); // Finish last path
output += makeCirclePath(color,paths.join(''));
});
return output;
}
var window = window || {};
window.CP = {
shouldStopExecution: function(){ return false; },
exitedLoop: function(){}
};
var lums = getBrightness(img),
paths = lumsToPaths(lums),
output;
output = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -0.5 '+img.width+' '+img.height+'">\n<g stroke="#000" fill="none" stroke-linecap="square">' + paths + '</g></svg>'
// Send message back to the main script
return output;
};
// File Output
var outputDiv = document.getElementById('output');
function fileSize(str) {
var bytes = encodeURI(str).split(/%..|./).length - 1;
if ( bytes === 0 ) return 0;
var sizes = ['bytes', 'kb', 'mb', 'gb', 'tb'],
i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))),
size = bytes / Math.pow(1024, i);
return (Math.round(size * 100) / 100) + ' ' + sizes[i];
};
function download(data,fileName) {
var a = document.createElement("a");
document.body.appendChild(a);
//return function(){
var blob = new Blob([data], {type: "octet/stream"}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
a.remove();
}
function downloadLink(output,fileName,linkContent) {
var link = document.createElement('a');
link.setAttribute('href','#');
link.addEventListener('click',function(e){
e.preventDefault();
download(output,fileName+'.svg');
});
link.innerHTML = (linkContent || output );
return link;
}
function showOutput(output,fileName) {
var figure = document.createElement('figure'),
figCaption = document.createElement('figcaption');
figure.className = 'output';
figure.appendChild(downloadLink(output,fileName));
figCaption.className = 'output__details';
figCaption.innerHTML = '<em class="output__size">Output size: ' + fileSize(output) + '</em><pre contentEditable="true" class="output__raw">' + output.replace(/</g,'<').replace(/>/g,'>') + '</pre>';
figCaption.insertBefore(downloadLink(output,fileName,'<span class="download">Download SVG</span>'),figCaption.childNodes[0]);
figure.appendChild(figCaption);
outputDiv.insertBefore(figure,outputDiv.childNodes[0]);
console.timeEnd('conversion');
}
// Convert image to canvas ImageData
function imageToData(img) {
var canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d"),
width = img.naturalWidth || img.width,
height = img.naturalHeight || img.height,
maxSize = window.maxSize || 512,
greater = ( width >= height ? width : height ),
scale = maxSize / greater;
if ( greater > maxSize ) {
height = height * scale;
width = width * scale;
}
canvas.width = width;
canvas.height = height;
ctx.drawImage(img,0,0,width,height);
return ctx.getImageData(0,0,width,height);
}
var imageWorker = cw(convertImage);
function convert(img,fileName){
img = (img.type ? this : img ); // use `this` if `img` is event
if ( !img || img === window ) { return false; }
console.time('conversion');
fileName = fileName || 'pixels';
var imgData = imageToData(img);
if ( !Modernizr.webworkers || !Modernizr.blobworkers ) {
console.log('No workers or blog support. Larger images may timeout.');
var converted = convertImage(imgData);
showOutput(converted,fileName);
} else {
imageWorker.data(imgData).then(function(converted){
showOutput(converted,fileName);
},function(e){
outputDiv.innerHTML = outputRaw.innerHTML = "";
console.error(e);
console.timeEnd('conversion');
});
}
}
function makeImage(src,callback){
var img = new Image();
img.onload = callback;
img.src = ( src.target ? src.target.result : src );
}
function loadFiles(e){
var files = (e.target.files || e.dataTransfer.files || uploader.files),
len = files.length,
i = 0;
each(files,function(i,file){
var reader = new FileReader();
var fileName = file.name;
fileName = fileName.slice(0,fileName.lastIndexOf('.')) || fileName + "";
reader.onload = function(e){
console.log(e,arguments);
makeImage(e,function(img){ convert(this,fileName); });
}
reader.readAsDataURL(files[i]);
});
}
// File Uploader
var uploader = document.getElementById('upload');
uploader.onchange = loadFiles;
// Test Image Conversion
var test = document.getElementById('test');
var testImage = document.getElementById('testImage');
test.onclick = function(){ convert(testImage,'test'); }
// Clear Output
var clear = document.getElementById('clear');
clear.onclick = function(){ output.innerHTML = ""; };
// Drag & Drop
var fileDrag = document.getElementById('filedrag');
function FileDragReset(e){
e.preventDefault();
fileDrag.className = '';
}
function FileDragDrop(e){
e = e || window.event;
FileDragReset(e);
loadFiles(e);
}
fileDrag.addEventListener("dragleave", FileDragReset);
document.addEventListener("dragenter", function(){ fileDrag.className = 'dragenter'; });
document.addEventListener('dragover',function(e){ e.preventDefault(); /* Essential! */ });
document.addEventListener("drop", FileDragDrop);
}());
Also see: Tab Triggers