I am using canvas with fabric js. I am trying to convert the canvas area in image , which works ok but when i resize the canvas and try to convert resized canvas to image it does not work. The board is getting expanded and then it converts to image, i think because of its inline width, How ever when i try to modify that inline width and height the fabric element does not work.
Here is my code
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/4.0.0-beta.12/fabric.js"></script>
<style>
select {
position: absolute;
top: 1000px;
}
</style>
<div id="lemu">
<canvas id='mycanvas' width='750' height='515' style='border:1px solid #000000;'></canvas>
</div>
<div class="japu">Click For Logo </div>
<img class="sf" src="" style="border:1px solid">
<script language="JavaScript">
$(document).ready(function () {
jQuery('.japu').click(function(){
var canstring = canvas.toDataURL("image/png", 1.0);
jQuery('img').attr('src',canstring);
});
var canvas = new fabric.Canvas('mycanvas');
fabric.Image.fromURL('https://fallbacks.carbonads.com/nosvn/fallbacks/731050e6bd3fc6979e1cb1a972294dae.png', function(img) {
var oImg = img.set({ left: 150, top: 0}).scale(0.4);
canvas.add(oImg);
});
jQuery('select').change(function(){
var valu = jQuery(this).val();
var candata = valu.split('x');
if(candata[0]==1){
jQuery('canvas').width(750);
}
else{
jQuery('canvas').width(candata[0]*20/2);
jQuery('.canvas-container').width(candata[0]*20/2);
}
});
});
</script>
<select><option value="1x1">36x24</option> <option value="36x48">36x24</option> <option value="36x48">36x96</option> </select>
Fiddle