Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">

<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

<div class = "buttons">

  <button class = "button" type="button" onclick="addTextToCanvas('quote')">Add Quote</button>

  <button class = "button" type="button" onclick="addTextToCanvas('author')">Add Author</button>

  <a href="" class = "button" onclick = "convertToImage()" id='downloader'>Download</a>

  <button type="button" id='delete' name="button">delete text layer</button>

</div>

<canvas id="myCanvas" width="800" height="500" style="border:1px solid #000000; margin-top  : 30vh;  margin-left : 25%">
</canvas>
<script src="https://cdn.jsdelivr.net/npm/fabric@4.6.0/dist/fabric.min.js" charset="utf-8"></script>
              
            
!

CSS

              
                
  body{
  color : black;
  font-family: 'Inter', sans-serif;
}
              
            
!

JS

              
                

  const canvas = new fabric.Canvas('myCanvas');
  canvas.backgroundColor = '#ffffff';
  //background color of canvas is white. If not mentioned, it will be transparent.


  var HideControls = {
          'tl':true, //topleft
          'tr':true, //topright
          'bl':true, //bottomleft
          'br':true, //bottomright
          'ml':false, //middleleft
          'mt':false, //middletop
          'mr':false, //middleright
          'mb':false, //middlebuttom
          'mtr':false //middlerotate
      };


//function to add text
//function is triggered by the button
  function addTextToCanvas(value){
    console.log(value);
    let textBox;

    if(value.trim()=='quote'){
      textBox = new fabric.IText("In order to love who you are, \nyou cannot hate the experiences \nthat shaped you.", {
          left : 70,
          top: 100,
          fontFamily: 'Inter',
          fontWeight: 'Bold',
          cornerColor: 'blue',
          cornerStrokeColor: 'red',
          borderColor: 'red',
          cornerSize: 12,
          padding: 10,
          textAlign: 'left',
          cornerStyle: 'circle',
          borderDashArray: [0, 0]
        });

    }else{
      textBox = new fabric.IText("Andrea Dykstra", {
          left : 70,
          top: 350,
          fontFamily: 'Inter',
          fontWeight: 'Normal',
          fontSize: '22',
          cornerColor: 'blue',
          cornerStrokeColor: 'red',
          borderColor: 'red',
          cornerSize: 12,
          padding: 10,
          textAlign: 'left',
          cornerStyle: 'circle',
          borderDashArray: [0, 0]});

    }

    canvas.add(textBox); //add the textbox variable into the canvas

    textBox.setControlsVisibility(HideControls); //hide controls such as scale, rotate, etc

    canvas.setActiveObject(textBox); //automatically selects the item in the canvas. Try without using this code.

  }




        var save = document.getElementById('downloader');
        save.addEventListener('click', sveimg, false);

        function sveimg(e) {
            this.href = canvas.toDataURL({
                format: 'png',
                quality: 0.8
            });
            this.download = 'canvas.png'
        }




 document.getElementById('delete').onclick = function() {
   var activeObject = canvas.getActiveObjects();

canvas.discardActiveObject();
canvas.remove(...activeObject);

      };


              
            
!
999px

Console