In my project I am showing image preview using canvas design. My original image is Original image
Using canvas I curved top and bottom like this Curved image.
But its top and bottom is jagged.
<!DOCTYPE HTML>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<section id="test"></section>
<script>
var image = new Image();
image.id = "imgBendSource";
image.style.display = "none";
image.onload = function() {
$("#test").append(image);
var newWidth = "415";
var newHeight = "285";
var img = document.getElementById("imgBendSource");
var x1 = 415 / 2;
var x2 = 415;
var y1 = 15; // input y of O here
var y2 = 0;
var eb = (y2 * x1 * x1 - y1 * x2 * x2) / (x2 * x1 * x1 - x1 * x2 * x2);
var ea = (y1 - eb * x1) / (x1 * x1);
var canvasHeight = parseInt(newHeight) + y1;
// create a new canvas for bend image
var canvasElement = '<canvas id="imgBendCanvas" width="' + newWidth + '" height="' + canvasHeight + '"/>';
$("#test").append(canvasElement);
canvasElement = document.getElementById("imgBendCanvas");
var bendCtx = canvasElement.getContext('2d');
for (var x = 0; x < newWidth; x++) {
// calculate the current offset
currentYOffset = (ea * x * x) + eb * x;
bendCtx.drawImage(img, x, 0, 1, newHeight, x, currentYOffset, 1, newHeight);
}
}
image.src = 'http://www.html5canvastutorials.com/demos/assets/darth-vader.jpg';
</script>
</body>
</html>
Is there any other way to achieve it? any plugins available?