-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
70 lines (60 loc) · 2 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Project : KineticJs Resize plugin
Description: A small Plugin I made for KineticJS to make resizing easy
Installation:
1.Download kinetic.plugin.resize.js
2.Include kinetic.plugin.resize.js after kinetic.js in HTML
Usage
var yodaImg; // name of the image
//define the width height of the Image
var width=93;
var height=104;
var KineticPlugins; /
//Make a stage
var stage = new Kinetic.Stage({
container: 'container',
width: 578,
height: 500
});
var layer = new Kinetic.Layer();
var imageObj = new Image();
// on image load
imageObj.onload = function() {
yodaImg = new Kinetic.Image({
x: 0,
y: 0,
image: imageObj,
width: width, //pass the width
height: height, //pass the height
name: "image"
});
//Plugin resize the image -
KineticPlugins = new Kinetic.Plugins.Resizable({
image : yodaImg, // Image Name
layer : layer, // Layer Name
stage : stage //Stage Name
});
//Initialize the Plugin (pass width and height of the image)
KineticPlugins.reSize(width, height );
};
imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/yoda.jpg'; // Image object
To maintain the aspect ratio of the image
-- replace
var width = topRight.getX() - topLeft.getX();
var height = bottomLeft.getY() - topLeft.getY();
if(width && height) {
image.setSize(width, height);
}
...by
var height = bottomLeft.attrs.y - topLeft.attrs.y;
var width = image.getWidth()*height/image.getHeight();
topRight.attrs.x = topLeft.attrs.x + width;
topRight.attrs.y = topLeft.attrs.y;
bottomRight.attrs.x = topLeft.attrs.x + width;
bottomRight.attrs.y = topLeft.attrs.y + height;
if(width && height) {
image.setSize(width, height);
}
--
For Multiple Image.
define the image again and also pass valid options
and initialize the plugin again .