cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

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.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <header class="container">
  <h1>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="-0.5 -0.5 100 16"><title>HalfTone.svg</title><g stroke="#000" fill="none" stroke-linecap="round"><path d="M0 0zm1 0zm1 0zm1 0zm4 0zm1 0zm1 0zm1 0zm10 0zm1 0zm1 0zm6 0zm1 0zm1 0zm2 0zm1 0zm1 0zm1 0zm1 0zm1 0zm1 0zm1 0zm1 0zm1 0z"/><path stroke-width=".96" d="M1 1zm1 0zm6 0zm1 0zm12 0zm1 0zm5 0zm3 0zm2 0zm1 0zm3 0zm1 0zm3 0zm1 0z"/><path stroke-width=".91" d="M1 2zm1 0zm6 0zm1 0zm12 0zm1 0zm4 0zm1 0zm5 0zm4 0zm1 0zm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m4 0zm1 0zm4 0zm1 0zm9 0zm1 0zm4 0zm1 0zm5 0zm1 0zm3 0zm1 0zm5 0zm1 0zm4 0zm1 0zm14 0zm1 0zm1 0zm1 0zm5 0zm1 0zm2 0zm4 0zm1 0zm4 0z"/><path stroke-width=".56" d="M1 9zm1 0zm6 0zm1 0zm3 0zm1 0zm3 0zm1 0zm4 0zm1 0zm4 0zm1 0zm9 0zm1 0zm4 0zm1 0zm5 0zm1 0zm3 0zm1 0zm5 0zm1 0zm4 0zm1 0zm12 0zm3 0zm1 0zm1 0zm5 0zm1 0zm1 0zm6 0zm1 0zm1 0zm1 0z"/><path stroke-width=".5" d="M1 10zm1 0zm6 0zm1 0zm3 0zm1 0zm2 0zm1 0zm1 0zm4 0zm1 0zm4 0zm1 0zm9 0zm1 0zm5 0zm1 0zm3 0zm1 0zm4 0zm1 0zm5 0zm1 0zm5 0zm1 0zm4 0zm3 0zm1 0zm3 0zm1 0zm3 0zm1 0zm6 0zm1 0zm5 0z"/><path stroke-width=".42" d="M0 11zm1 0zm1 0zm1 0zm4 0zm1 0zm1 0zm1 0zm3 0zm1 0zm2 0zm1 0zm1 0zm2 0zm1 0zm1 0zm1 0zm2 0zm1 0zm1 0zm1 0zm7 0zm1 0zm1 0zm1 0zm5 0zm1 0zm1 0zm1 0zm4 0zm1 0zm1 0zm1 0zm1 0zm2 0zm1 0zm1 0zm1 0zm5 0zm1 0zm1 0zm1 0zm4 0zm1 0zm3 0zm1 0zm1 0zm1 0zm1 0zm7 0zm1 0zm5 0zm1 0zm1 0zm1 0zm1 0zm1 0z"/><path stroke-width=".36" d="M93 12zm1 0zm1 0zm1 0zm1 0zm1 0zm1 0z"/><path stroke-width=".29" d="M92 13zm6 0zm1 0z"/><path stroke-width=".23" d="M91 14zm1 0zm6 0z"/><path stroke-width=".17" d="M92 15zm1 0zm1 0zm1 0zm1 0zm1 0z"/></g></svg>
</h1>
  
  <p>Pine for the days of cracking open a newspaper with beautiful half tone black and white prints? Recreate that magic (minus the ink smudges and paper smell) 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/XbxvNj" target="_top">Pixels.svg</a> and <a href="https://codepen.io/shshaw/pen/BNeBPq" target="_top">LinePrint.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/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAACtCAMAAABx2yoaAAAAS1BMVEUPBQX7+/v239jg5OnP2ODCxcy1trnsw7WjnZ3ZppiKhoWyhnrHbll0cnOPZFu4UTmRPTBuOzNgXFtJREQ+MS4qKClZFA6GGxQPBQUHPuDWAAAAAXRSTlMAQObYZgAAFqpJREFUeAGskokO3DoIRecGsCwquoCp+P8vfcHpTLqv78yaxOYIrh+/C0D8fDHw+L/ounPOcSI81dTc3VR1igiLjCH0LzqweoR7WBc18zgx98gVK6JvzzGntnEOYfpjwbC1MtTUTVfWhWtfen1OxltX3b3pKWX8bgcW6V45iWaEDq9NVp6stW5B3aiwsK7lTMK/UlBU+hQx1w4YAOmraE/Po74ktx8H06GZ5XN0W/ixYmT6GEOzBjYkw6Jq7fI9/H73y048fK2sJnDi21jpe4V+PyRx98l6bTrUrJf6iWmH3OfpRPoA97Gap2+bTNX645V7pr1fRtiQb/pBOs14zjpz2RSZ6rH6/3WCmPDkAJGMqb4yQ6f0ha+9ffX89tRNv9RIDfL6hKuIqGfvl12YuAsTWZzs7tq7n5GodVY+hbl3tSgjw2x8qdEkXjz7uek8ti9adfDQ6HBl9lGN6Mlcc8qT5TpIml4WUwbL0H06JiQmTefbAS2CVgkOb5UCGFN3Qstkd0PE/WnoHhztoS0bfasH7gIcVt7P3KF+ObjAtaBlOFZVzgMYkS2xia3zyPqaTLceWcMauVzak1VGgLoRpBZmbEkaVmXUgFXl6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66kkYmLmCTMefH93jlb7smQeQ2CQLtFesZrZN0dVYR8MIysv+7unS7n7JE6f7kJLjUvXURL02w6rsrIZweK+QFMSw+BmIUQvXtLtb7fUNqoW4kORhhnHPOAKo1pnSvSYSxbJK4LNHgBr4lPjOI58WsPYXbeGdeetZrZegl2B1ZWOyILT3NmECzrHo4MVzMV0et1tqh6ZObeFxA263hNzGP0S/pmDCUdZ7sh3iiT/nRSPQb1UnXN9b2w9+FP2LObiI8IyWfjFU/4Nye6tEdls4/lOYCAQ1V184j8VoS7PanAOggegDAhs3cH2Q0Fn4iRXLjxzVQRkC7mXAlxDQvpiEf0LJ7LK/t7Q0CdMQ0lnTrLZ/i3mW6f/ntOywnh48u/n9/Tuyv86FlFFIs+Sr5m2uGvIM4a5q26EA+n04VeFXsyprmOfkYfomUNQLJFvLod//TXdMFofeRTX/NMm65nmhDCCAHn7tFUVMyjjnq2uXB2xLR1gv03ArkpTVNFRc0y6+o2+8iGnHf1/afMJiI8Fo5KBvE/iTTnaJqZyoWZ+cPqG3nuDjR9dtzwoqZxCYr/h3+OoPEEzTupL6nIcx3xvY4sH7YP4f8mQLZ4CnCTFr2X0ZDsyMdgj8J4RufvFdKTaQ1t9O7GqNKVJvw/Q4A4uG89X8JP9v9P9Bf/3h4TpF3zRAAAAABJRU5ErkJggg==" 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: 'Times', 'Times New Roman', serif;
  padding: 1em;
  padding-bottom: 2em;
  margin: auto;
  font-size: 16px;
  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(){};

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 / 200 ).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(''));
      });
      
      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.5 -0.5 '+img.width+' '+img.height+'">\n<g stroke="#000" fill="none" stroke-linecap="round">' + paths + '</g>\n<desc>Generated by HalfTone.svg v1.0</desc></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,'&lt;').replace(/>/g,'&gt;') + '</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);

}());
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console