A Pen by Edward Lance Lorilla on CodePen.
Created
November 5, 2019 14:42
-
-
Save edwardlorilla/5d014850dd2399899109de3b13f107f1 to your computer and use it in GitHub Desktop.
meme creator vuejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"> | |
<div> | |
<input type="file" id="fileinput" @change="onFileChange"> | |
</div> | |
<div> | |
<label for="topText">Top Text:</label> | |
<input type="text" v-model="topText" class="form-control" /> | |
</div> | |
<div > | |
<label for="bottomText">Bottom Text:</label> | |
<input type="text" v-model="bottomText" class="form-control" /> | |
</div> | |
<canvas ref="canvas" id= "canvas"></canvas> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Vue({ | |
data(){ | |
return{ | |
topText: '', | |
bottomText: '' | |
} | |
}, | |
methods:{ | |
onFileChange(e) { | |
var files = e.target.files || e.dataTransfer.files; | |
if (!files.length) | |
return; | |
this.createImage(files[0]); | |
}, | |
createImage(file) { | |
var vm = this; | |
var reader = new FileReader(); | |
var image = new Image(); | |
reader.readAsDataURL(file); | |
reader.onload = (e) => { | |
image.onload = (ev) => { | |
var canvas = this.$refs.canvas; | |
canvas.width = image.width; | |
canvas.height = image.height; | |
var ctx = canvas.getContext('2d'); | |
ctx.clearRect(0, 0,canvas.height, canvas.width) | |
ctx.drawImage(image,0,0); | |
var e = (canvas.width + canvas.height) / 2 * 4 / 100; | |
ctx.font = e + "pt sans-serif" | |
ctx.textAlign = "center" | |
ctx.textBaseline = "top" | |
ctx.lineWidth = e / 5 | |
ctx.strokeStyle = "black" | |
ctx.fillStyle = "white" | |
ctx.lineJoin = "round"; | |
var t = vm.topText.toUpperCase(), | |
n = vm.bottomText.toUpperCase(); | |
ctx.strokeText(t, canvas.width / 2, .05 * canvas.height) | |
ctx.fillText(t, canvas.width / 2, .05 * canvas.height) | |
ctx.strokeText(n, canvas.width / 2, .9 * canvas.height) | |
ctx.fillText(n, canvas.width / 2, .9 * canvas.height) | |
} | |
image.src = e.target.result; | |
}; | |
}, | |
} | |
}).$mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment