Advertisement
KoctrX

Untitled

Jan 27th, 2023
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function createImageAppend(padding = 10, width = 200, height = 120) {
  2.     const img = await new Promise(resolve => fabric.Image.fromURL('/pdf-templates/img/image.svg', resolve));
  3.     const text = new fabric.Text('Select image', {
  4.         fontSize: 16, fill: '#8C49F7',
  5.         left: 30, fontFamily: 'Arial'
  6.     });
  7.  
  8.     // img.set({ left: padding, top: padding });
  9.     // text.set({
  10.     //     left: padding + padding + img.width * img.scaleX,
  11.     //     top: padding + (img.height) / 4
  12.     // });
  13.  
  14.    
  15.     const rect = new fabric.Rect({
  16.         left: 0, top: 0, fill: '#f9f9f9',
  17.         width, height
  18.     });
  19.  
  20.     const calculateInsert = () => {
  21.        
  22.     };
  23.  
  24.     img.top = rect.height / 2 - img.height / 2;
  25.     img.left = (rect.width - (img.width + text.width + padding)) / 2;
  26.  
  27.  
  28.     text.set({
  29.         top: rect.height / 2 - text.height / 2,
  30.         left: img.left + img.width + padding
  31.     });
  32.  
  33.     calculateInsert();
  34.    
  35.     const group = new fabric.Group([rect, img, text], { left: 100, top: 100 });
  36.     return group;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement