Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <div class="container">
	
<div class="w3-container w3-panel">
<h2>Meme Generator</h2>
<input class="w3-input w3-border" id="file" type="file">
</div>

<div class="w3-container w3-panel">
<input class="w3-input w3-border" id="topLineText" type="text" placeholder="Text Oben">
</div>	
	
<div class="w3-container">
<canvas id="image" width="1000" height="500" class="w3-card-4"></canvas>
</div>
	
<div class="w3-container w3-panel">
<input class="w3-input w3-border" id="bottomLineText" type="text" placeholder="Text Unten">
</div> 
	
<div class="w3-container w3-panel">
<button id="saveBtn" class="w3-button w3-blue">Speichern</button>
</div>
	
</div>
            
          
!

CSS

            
              * { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #fff; color: #000; }
canvas { max-width: 100%; height: auto; }
.container { background: #fff; max-width: 70em; margin: 0 auto; width: 95%; }
            
          
!

JS

            
              function textChangeListener (evt) {
var id = evt.target.id;
var text = evt.target.value;
if (id == "topLineText") {
window.topLineText = text; }
else { window.bottomLineText = text; }
redrawMeme(window.imageSrc, window.topLineText, window.bottomLineText);
}

function redrawMeme(image, topLine, bottomLine) {
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext("2d");
if (image != null){
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
}
ctx.font = "4rem Impact";
ctx.textAlign = "center";
ctx.strokeStyle = "black";
ctx.lineWidth = 1;
ctx.fillStyle = "white";
if (topLine != null){
ctx.fillText(topLine, canvas.width / 2, 70);
ctx.strokeText(topLine, canvas.width / 2, 70);
}
if (bottomLine != null){
ctx.fillText(bottomLine, canvas.width / 2, canvas.height -30);
ctx.strokeText(bottomLine, canvas.width / 2, canvas.height -30);
}
}

function saveFile() {
window.open(document.querySelector('canvas').toDataURL());
}

function handleFileSelect(evt) {
var canvasWidth = 300;
var canvasHeight = 300;
var file = evt.target.files[0];
var reader = new FileReader();
reader.onload = function(fileObject) {
var data = fileObject.target.result;
var image = new Image();
image.onload = function() {
window.imageSrc = this;
redrawMeme(window.imageSrc, null, null);
}
image.src = data;
console.log(fileObject.target.result);
};
reader.readAsDataURL(file)
}

window.topLineText = "";
window.bottomLineText = "";
var input1 = document.getElementById('topLineText');
var input2 = document.getElementById('bottomLineText');
input1.oninput = textChangeListener;
input2.oninput = textChangeListener;
document.getElementById('file').addEventListener('change', handleFileSelect, false);
document.querySelector('button').addEventListener('click', saveFile, false);
            
          
!
999px

Console