css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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

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

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="browserNotification">For the best possible experience, please use Chrome or Firefox to view this page</div>

<div class="screen">
  <div>
    <div class="screen1">
      <h1>Welcome to <a href="https://www.aweber.com" target="_blank">AWeber’s</a> Duo-Tone Filter for&nbsp;Email&nbsp;Images!</h1>
      <p>
        <a href="https://designmodo.com/duotone-website-design/" target="_blank">Duo-tone</a> images are a great way to add a playful, yet sophisticated look and feel to your emails. Choose the color you’d like to apply to an image then drag the image into the box below (or upload an image).
      </p>
    </div>

    <div class="screen2">
      <h2>All done duo-toning!</h2>
      <p>
        Download the image and add it to your email (We recommend using AWeber's "West" template)! Enjoy!
      </p>
      <div class="element">
        <a onclick="startOver()" class="btn btn--secondary">Start Over</a>
        <a onclick="downloadIt()" class="btn">Download</a>
      </div>
    </div>
  </div>
  
  <div>
    <div class="screen__elements">
      <div class="element">
        <label for="custom"><strong>Pick a color:</strong> </label><input type='text' name="color" id="color" /><br>
      </div>

      <div class="element advanced">
        <a onClick="advancedTray(this)">advanced options</a>
        <div id="advancedOptions" class="advanced__options">
          <label for="contrast"><strong>Contrast:</strong> </label><input id="contrast" type="range" min="0.5" max="2" step="0.1" /><input type="number" id="contrastNum" min="0.5" max="2" step="0.1" /><br>
          <label for="blendMode"><strong>Blend Mode:</strong> </label>
          <select id="blendMode">
            <option value="multiply">Multiply</option>
            <option value="overlay">Overlay</option>
            <option value="screen">Screen</option>
            <option value="luminosity">Luminosity</option>
            <option value="color-dodge">Color Dodge</option>
            <option value="color-burn">Color Burn</option>
          </select>
        </div>
      </div>

      <div class="screen1">
        <div id="dropZone">Drop your image here</div>

        <div class="element">
          <label for="file" class="file">Or choose a file</label>
          <input type="file" name="file" id="file" accept="image/*" capture>
        </div>
      </div>

      <div class="screen2">
        <div class="screen__elements">
          <canvas id="image" class="finalImage"></canvas>
        </div>
      </div>

    </div>
  </div>
</div>

<div class="builtBy">
  <img src="https://preview.ibb.co/m3m6Hk/Pixel_Team.gif" alt="Pixel Team" border="0" width="54" /><br>
  Made by Kim and Chris from&nbsp;<a href="https://www.aweber.com" target="_blank">AWeber</a>,<br/>
  an absolutely AWesome email company.<br>
</div>
            
          
!
            
              $borderRad: 12px;
$bgColor: #EEEEEE;
$fontColor: #4a4a4a;
$primary: #08AAC7;
$secondary: #CCCCCC;
$canvasWidth: 600px;
$boxShadow: rgba(0, 0, 0, 0.2) 0px 6px 8px -4px;

body {
  background-color: $bgColor;
  color: $fontColor;
  font-family: helvetica, arial, sans-serif;
  font-size: 16px;
  line-height: 1.3;
  text-align: center;
}

a {
  color: $primary;
  font-weight: 700;
  text-decoration: none;
  transition-duration: 0.3s;
  
  &:hover {
    color: darken($primary, 5%);
  }
}

h1,
h2 {
  font-size: 1.5em;
  text-align: left;
  
  a {
    color: $fontColor;
    text-decoration: underline;
  }
}

p {  
  margin-bottom: 36px;
  text-align: left;
  
  a {
    color: $fontColor;
    text-decoration: underline;
  }
}

// @TODO fix browser issues so you can remove this!
.browserNotification {
  background-color: darken($bgColor, 5%);
  font-size: 14px;
  padding: 8px;
  position: fixed;
  text-align: center;  
  top: 0;
  width: 100%;
  z-index: 200;
}

.screen {
  display: flex;
  flex-wrap: wrap;
  max-width: 960px;
  margin: 50px auto 0;
  width: 100%;
  
  > div {
    &:first-child {
      width: 33%;
    }
    
    &:last-child {
      width: 66%;
    }
    
    @media screen and (max-width: 960px) {
      flex-basis: 100%;
    }
  }
  
  .screen2 {
    display: none;
  }
  
  &__elements {
    margin: 10px auto 40px;
    max-width: $canvasWidth;
    width: 100%;
  }
}

.builtBy {
  background-color: $bgColor;
  box-sizing: border-box;
  color: lighten($fontColor, 15%);
  font-size: 0.8em;
  line-height: 1.3;
  padding: 5px 20px 20px;
}

.element {
  display: block;
}

// Advanced Options
.advanced {
  margin-top: 0.5rem;
  
  a {
    font-size: 0.8rem;
    font-weight: 400;
  }
  
  &__options {
    background: lighten($secondary, 10%);
    border: 1px solid $secondary;
    border-radius: $borderRad;
    display: none;
    padding: 0.5rem;
  }
}

.btn,
label.file,
.sp-button-container .sp-choose {
  background: $primary;
  border: none;
  border-radius: $borderRad * 2;
  color: #FFFFFF;
  cursor: pointer;
  display: inline-block;
  font-weight: 500;
  margin-bottom: 1rem;
  padding: 10px 15px;
  transition-duration: 0.3s;
  
  &:hover {
    color: #FFFFFF;
    background: darken($primary, 5%);
    border: none;
  }
  
  &--secondary {
    background: $secondary;
    color: $fontColor;
    
    &:hover {
      background: darken($secondary, 5%);
      color: $fontColor;
    }
  }
}

label.file {
  border-radius: 0 0 $borderRad $borderRad;
  box-shadow: $boxShadow;
  display: block;
  padding: 15px;
}

.sp-button-container .sp-choose {
  margin: 0;
  padding: 10px;
}

input[type="file"] {
  display: none;
}

#dropZone {
  background-color: #ffffff;
  border: 2px dashed $secondary;
  border-bottom: none;
  border-radius: $borderRad $borderRad 0 0;
  box-sizing: border-box;
  clear: both;
  cursor: pointer;
  margin: 20px auto 0;
  padding: 80px;
  transition: opacity 0.3s ease-in-out;
}

.finalImage {
  box-shadow: $boxShadow;
  height: auto;
  left: 0;
  margin-bottom: 10px;
  max-width: $canvasWidth;
  opacity: 0;
  
  &#snapshot {
    opacity: 1;
  }
}


// Color Picker
.sp-replacer {
  background: white;
  border-color: $secondary;
  border-radius: $borderRad / 2;
  padding: 3px;
  
  &.sp-active {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-width: 0;
    border-color: $primary;
  }
  
  .sp-preview {
    border-width: 0;
    border-radius: $borderRad / 4;
    margin-right: 3px;
    overflow: hidden;
  }
  
  .sp-dd {
    padding-right: 3px;
  }
}

.sp-container {
  background: #FFFFFF;
  border-radius: 0 $borderRad/2 $borderRad/2;
  border-color: $primary;
  margin-top: -1px;
}
            
          
!
            
              console.clear();

// TODO: Add message for unsupported browsers.
var canvas = document.getElementById('image'),
    input = document.getElementById('file'),
    theImg,
    blendColor = "#80c4c2",
    contrast = 1.2,
    ctx = canvas.getContext('2d'),
    fadeTime = 120,
    currentFilter = 'grayscale(100%)',
    currentBlend = 'multiply';

// Pass image to render function
function loadImage(src){
  var reader = new FileReader();
  reader.onload = function(e){
    render(e.target.result);
  };
  reader.readAsDataURL(src);
}


// Draw image to canvas and apply filters
function render(src){
  var image = new Image();
  
  image.onload = function(){
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    canvas.width = image.width;
    canvas.height = image.height;
    ctx.fillStyle = blendColor;
    ctx.fillRect(0,0,canvas.width,canvas.height);
    // @TODO find solution for no .filter support in IE or Safari. Consider this approach: https://www.html5rocks.com/en/tutorials/canvas/imagefilters/
    ctx.filter = currentFilter + ' contrast(' + contrast + ')';
    ctx.globalCompositeOperation = currentBlend;
    ctx.drawImage(image, 0, 0, image.width, image.height);
  };
  
  image.src = src;
}


// Download contents on canvas using filesaver.js
// @Todo investigate bug downloading in Safari
function downloadIt(){
  canvas.toBlob(function(blob) {
    saveAs(blob, "duotone.png");
  }, "image/png");
}


// Go back to first step and reset canvas
function startOver(){
  screenFade();
}


// Fade between stages of the screen
function screenFade(){
  // Go from step 1 to step 2
  if($('.screen1').is(':visible')){
    $('.screen1').fadeOut(fadeTime, function(){
      $('.screen2').fadeIn(fadeTime, function(){
        $('#image').animate({
          marginTop: '0',
          opacity: '1'
        }, 300);
      });
    });
  }
  // Go from step 2 to step 1 and clear the canvas
  else {
    $('.screen2').fadeOut(fadeTime, function(){
      $('.screen1').fadeIn();
      $('#image').css({
        marginTop: '10px',
        opacity: '0'
      });
      ctx.clearRect(0, 0, canvas.width, canvas.height);
    });
  }
}


// Set up dropzone
var target = document.getElementById('dropZone');
target.addEventListener("dragover", function(e){e.preventDefault();}, true);
target.addEventListener("drop", function(e){
	e.preventDefault(); 
  theImg = e.dataTransfer.files[0];
	loadImage(theImg);
  screenFade();
}, true);


// Set up filepicker button
input.addEventListener("change", function(e) {
  e.preventDefault();
  theImg = e.srcElement.files[0];
  loadImage(theImg);
  screenFade();
}, true);


// Initialize Spectrum color picker
$("#color").spectrum({
  color: blendColor,
  showInput: true,
  preferredFormat: "hex",
  change: function(color) {
    blendColor = color.toHexString();
    ctx.fillstyle = blendColor;
    ctx.fillRect(0,0,canvas.width,canvas.height);
    if(theImg){
      loadImage(theImg);
    }
  }
});


// Init Contrast Slider
$('#contrast').val(contrast);
$('#contrastNum').val(contrast);
function contrastChange(inpt, inpt2){
  $(inpt).on('input', function(){
    contrast = $(this).val();
    $(inpt2).val(contrast);
    if(theImg){
      loadImage(theImg);
    }
  });
}
contrastChange('#contrast', '#contrastNum');
contrastChange('#contrastNum', '#contrast');


// Init blend mode picker
$('#blendMode').on('input', function(){
  currentBlend = $(this).val();
  if(theImg){
    loadImage(theImg);
  }
});


// Slide open advanced tray
function advancedTray(trig){
  $(trig).fadeOut(200, function(){
    $('#advancedOptions').fadeIn();
  });
}
            
          
!
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