0.0.5 • Published 10 months ago

shapes-plus v0.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

Update

1- Fix some problim

Resorce

Compiling for node js only

If you want to know the details, go here

OSCommand
OS XUsing Homebrew:brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
Ubuntusudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
Fedorasudo yum install gcc-c++ cairo-devel pango-devel libjpeg-turbo-devel giflib-devel
Solarispkgin install cairo pango pkg-config xproto renderproto kbproto xextproto
OpenBSDdoas pkg_add cairo pango png jpeg giflib
WindowsSee the wiki
OthersSee the wiki

Install

npm

npm install shapes-plus --save
// index.js
const { Shapes } = require("shapes-plus");
const shapes = new Shapes(/* options: ShapesOptions */);

or

// index.js
import { Shapes } from "shapes-plus";
const shapes = new Shapes(/* options: ShapesOptions */);

Values

KeyType
createCirclemethod
createTextmethod
createImagemethod
createLinemethod
createRectmethod
createRhombusmethod
createStarmethod
createTrianglemethod
toBuffermethod
toSavemethod
addFontFamilymethod
Canvasprototype
canvasprototype
ctxprototype

Rect

const rect = shapes.createRect(/* options: RectOptions */);
rect.draw({x:200, y:100, color:"blue", drawType:"stroke"})
rect.draw({x:500, y:100, height:110, width:110});

Rect

Circle

const circle = shapes.createCircle(/* options: CircleOptions */);
circle.draw({x:200, y:100, color:"blue", drawType:"stroke"});
circle.draw({x:500, y:100, radius:60});

Circle

Text

const text = shapes.createText(/* options: TextOptions */);
text.draw({x:200, y:100, color:"blue", drawType:"stroke", text:"Hello"});
text.draw({x:500, y:100, text:"Hi", fontFamily:"Impact", size:60, textAlign:"left", width:70});

Text

Line

const line = shapes.createLine(/* options: LineOptions */);
line.draw({x:200, y:100, endX:450, endY:100, color:"blue", lineWidth:3});
line.draw({x:200, y:150, endX:450, endY:150, lineWidth:5});

Line

Rhombus

const rhombus = shapes.createRhombus(/* options: RhombusOptions */);
rhombus.draw({x:200, y:200, color:"blue", drawType:"stroke"});
rhombus.draw({x:500, y:200, height:80 ,width:90});

Rhombus

Star

const star = shapes.createStar(/* options: StarOptions */);
star.draw({x:200, y:100, color:"blue", drawType:"stroke"});
star.draw({x:500, y:100, spikes:9, innerRadius:20, outerRadius:30});

Star

Image

const image = shapes.createImage(/* options: ImageOptions */);
image.draw({x:200, y:500, height:120, width:120, path:"https://cdn.discordapp.com/attachments/716228498825412690/987695097107873792/unknown.png"}).then(async img=>
    {
        await image.draw({x:400, y:500, isCircle:true, radius:60, path:"https://cdn.discordapp.com/attachments/716228498825412690/987695097107873792/unknown.png"});
        await img.draw({x:600, y:500, height:100, width:100, path:"https://cdn.discordapp.com/attachments/716228498825412690/987695097107873792/unknown.png"});
        await img.draw({x:800, y:500, isCircle:true, radius:50, path:"https://cdn.discordapp.com/attachments/716228498825412690/987695097107873792/unknown.png"});
    });

Image

Triangle

const triangle = shapes.createTriangle(/* options: TriangleOptions */);
triangle.draw({x:200, y:100, color:"red"});
triangle.draw({x:300, y:100, color:"blue", drawType:"stroke"});
triangle.draw({x:400, y:100, color:"green", rotate:70});
triangle.draw({x:200, y:200, color:"yellow", sideAB: 20, sideAC: 10});
triangle.draw({x:300, y:200, color:"pink", sideBC: 50, rotate:20});

Triangle

Font Family

Warning If you use windows os you must add font family in your windows before use addFontFamily

// Add new Font Family 
const { addFontFamily } = require("shapes-plus");
addFontFamily(/* path: string, setName: string */) // You can add any name in setName

Or

// Add new Font Family 
import { addFontFamily } from "shapes-plus";
addFontFamily(/* path: string, setName: string */) // You can add any name in setName

for examlpe:

addFontFamily("./Halimun.ttf","Halimun");

const text = shapes.createText();
text.draw({x:200, y:100, text:"Hello", fontFamily:"Halimun"});
text.draw({x:500, y:100, text:"Hello", fontFamily:"Impact"});

font family

Other method

// save Image
shapes.toSave(path); // path = "save local device without extension"

// convert to Buffer
shapes.toBuffer() // return Buffer

One example in detail

shapes.createRect(/*options*/).draw({x:500, y:100, color:"red"}).draw({x:700, y:100, color:"red"}).draw({x:900, y:100, color:"red"});

OR

shapes.createRect({y:100, color:"red"}).draw({x:500}).draw({x:700}).draw({x:900});

OR

const rect = shapes.createRect(/*options*/);
rect.draw({x:500, y:100, color:"red"});
rect.draw({x:700, y:100, color:"red"});
rect.draw({x:900, y:100, color:"red"});

OR

const rect = shapes.createRect({color:"red", y:100});
rect.draw({x:500});
rect.draw({x:700});
rect.draw({x:900});

draws

Options

ShapesOptions

KeyTypeDefault
width?Number1920
height?Number1080
canvas?CanvasCanvas

RectOptions

KeyTypeDefault
xNumber0
yNumber0
colorStringblack
drawType drawStringfill
widthNumber100
heightNumber100

CircleOptions

KeyTypeDefault
xNumber0
yNumber0
colorStringblack
drawType drawStringfill
radiusNumber50

TextOptions

KeyTypeDefault
xNumber0
yNumber0
colorStringblack
drawType drawStringfill
widthNumber100
textStringnull
sizeNumber50
fontFamilyStringArial

LineOptions

KeyTypeDefault
xNumber0
yNumber0
colorStringblack
lineWidthNumber1
endXNumber50
endYNumber50

RhombusOptions

KeyTypeDefault
xNumber0
yNumber0
colorStringblack
drawType drawStringfill
widthNumber100
heightNumber100
lineWidthNumber1

StarOptions

KeyTypeDefault
xNumber0
yNumber0
colorStringblack
drawType drawStringfill
lineWidthNumber1
spikesNumber5
outerRadiusNumber30
innerRadiusNumber15

ImageOptions

KeyTypeDefault
xNumber0
yNumber0
colorStringblack
widthNumber100
heightNumber100
pathStringnull

TriangleOptions

KeyTypeDefault
xNumber0
yNumber0
colorStringblack
drawType drawStringfill
sideAB?number0
sideAC?number0
sideBC?number0
rotate?number0
0.0.5

10 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.0

11 months ago