Skip to content

Commit 7dc0ed1

Browse files
author
Kendo Bot
committed
Sync with Kendo UI Professional
1 parent 4b529fd commit 7dc0ed1

File tree

599 files changed

+1322
-919
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

599 files changed

+1322
-919
lines changed

docs-aspnet/html-helpers/editors/imageeditor/tools.md

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,92 @@ position: 2
1010

1111
The ImageEditor provides a predefined collection of tools that are used to interact with the control.
1212

13-
You can enable any of these tools by using the `Tools()` HtmlHelper method and configure it with the specific tool method.
13+
You can enable any of these tools by using the `Toolbar()` HtmlHelper method and configuring the Items collection to add the required tools.
1414

1515
## Default Tools
1616

17-
The default tools in the ImageEditor are included in the toolbar of the ImageEditor upon setting the respective tool method.
17+
By default, all tools of the ImageEditor are included in the Toolbar.
1818

19-
The following example demonstrates how to instantiate an ImageEditor with predefined set of tools.
19+
The following example demonstrates how to instantiate an ImageEditor with predefined set of tools and add a custom button to the ImageEditor Toolbar.
2020

2121
```
2222
@(Html.Kendo().ImageEditor()
2323
.Name("imageEditor")
24-
.Tools(tools => tools
25-
.Open()
26-
.Save()
27-
.Crop()
28-
.Resize()
29-
)
24+
.Toolbar(toolbar=>toolbar.Items(i=> {
25+
i.Add().Name("open");
26+
i.Add().Name("save");
27+
i.Add().Name("resize");
28+
i.Add().Name("crop");
29+
i.Add().Name("undo");
30+
i.Add().Name("redo");
31+
i.Add().Name("zoomIn");
32+
i.Add().Name("zoomOut");
33+
i.Add().Name("zoomDropdown");
34+
i.Add().Type("separator");
35+
i.Add().Type("button").Name("myButton").Text("Custom Button").Click("onButtonClick");
36+
}))
3037
)
38+
39+
<script>
40+
function onButtonClick() {
41+
kendo.alert("button clicked!")
42+
}
43+
</script>
44+
```
45+
46+
## Adding Custom Commands to the Toolbar
47+
48+
The kendo.ui.imageeditor namespace exposes the ImageEditorCommand class that could be extended to implement a custom ImageEditor command. The example below demonstrates how to create a custom command that creates a thumbnail from the loaded image.
49+
50+
First, create a new command by extending the ImageEditorCommand class.
51+
52+
```
53+
<script>
54+
var imageEditorNS = kendo.ui.imageeditor;
55+
56+
imageEditorNS.commands.MakeThumbnailImageEditorCommand = imageEditorNS.ImageEditorCommand.extend({
57+
exec: function () {
58+
var that = this,
59+
options = that.options,
60+
imageeditor = that.imageeditor,
61+
canvas = imageeditor.getCanvasElement(),
62+
ctx = imageeditor.getCurrent2dContext(),
63+
image = imageeditor.getCurrentImage();
64+
65+
var origWidth = canvas.width;
66+
ctx.clearRect(0, 0, canvas.width, canvas.height);
67+
if((canvas.width / canvas.height) < 0){
68+
canvas.width = 200;
69+
canvas.height = origWidth*(200 / canvas.height);
70+
} else {
71+
canvas.width = origWidth/(canvas.height/200);
72+
canvas.height = 200
73+
}
74+
75+
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
76+
77+
imageeditor.drawImage(canvas.toDataURL()).done(function(image){
78+
imageeditor.drawCanvas(image);
79+
}).fail(function (ev) {
80+
imageeditor.trigger("error", ev);
81+
});
82+
}
83+
});
84+
</script>
85+
```
86+
87+
Then add the custom command to the ImageEditor Toolbar:
88+
3189
```
90+
.Toolbar(toolbar=>toolbar.Items(i=> {
91+
i.Add().Command("MakeThumbnailImageEditorCommand").Type("button").Text("Make Thumbnail");
92+
}))
93+
```
94+
95+
## Loading Images in the ImageEditor
96+
97+
If the ImageUrl configuration option is used to set a predefined image for the ImageEditor and the image is hosted on another domain, the image editing tools will be disabled. If loading of an image from another domain is required provide the image as base64string. When the image is loaded from the same domain make sure a relative path to the image is used or the image is provided as base64string.
98+
3299

33100
## See Also
34101

26.5 KB
Loading
Binary file not shown.
17.3 KB
Loading
5.73 KB
Loading
38.9 KB
Loading
42.8 KB
Loading
-4.92 KB
Loading
Binary file not shown.
50.2 KB
Loading

0 commit comments

Comments
 (0)