Is it possible to click on the crop button without the crop form window opening ?

1 Answer 21 Views
ImageEditor
Thor
Top achievements
Rank 1
Thor asked on 08 Mar 2024, 09:09 AM
Is it possible to click on the crop button without the crop form window opening, but that you can crop and then have another save changes button, preferably under images where you crop ?

Need the same function for the Save button also, I just want the save button to go to code behind and I will do the saving :-)

1 Answer, 1 is accepted

Sort by
0
Vasko
Telerik team
answered on 11 Mar 2024, 02:03 PM

Hi Thor,

You can remove the crop/save popup window by setting it's display CSS property to false:

<style>
    #RadImageEditor1_ToolsPanel {
        display: none !important;
    }
</style>

Now only the crop dimensions will be shown, and they will be needed for the x/y position, as well as the width/height of the crop area: 

<telerik:RadImageEditor ID="RadImageEditor1" runat="server" ImageUrl="images.jpg">
    <Tools>
        <telerik:ImageEditorToolGroup>
            <telerik:ImageEditorTool CommandName="Crop" />
            <telerik:ImageEditorTool CommandName="Save" />
        </telerik:ImageEditorToolGroup>
    </Tools>
</telerik:RadImageEditor>

<telerik:RadButton runat="server" ID="RadButton1" Text="Crop" AutoPostBack="false" OnClientClicked="OnClientClicked" />
<script>
    function OnClientClicked(sender, args) {
        var imgEditor = $find("<%= RadImageEditor1.ClientID %>");
        imgEditor.getEditableImage().crop(collectBounds());
    }

    function collectBounds() {
        var imgEditor = $find("<%= RadImageEditor1.ClientID %>");
        var draggableResizeBox = document.querySelector(".rieDraggableResizeBox")

        if (draggableResizeBox) { // Crop only if the crop box is selected
            var xPos = parseInt(draggableResizeBox.style.left.replace("px", "")); // Parse the values to numbers
            var yPos = parseInt(draggableResizeBox.style.top.replace("px", ""));
            var width = parseInt(draggableResizeBox.style.width.replace("px", ""));
            var height = parseInt(draggableResizeBox.style.height.replace("px", ""));

            if (isNaN(xPos) || isNaN(yPos) || isNaN(width) || isNaN(height)) {
                return false;
            }

            return new Sys.UI.Bounds(xPos, yPos, width, height); // The ImageEditor expects certain bounds to be applied when attempting to crop, and the values are from the draggableResizeBox itself
        }
    }
</script>

I hope this helps.

Kind regards,
Vasko
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Tags
ImageEditor
Asked by
Thor
Top achievements
Rank 1
Answers by
Vasko
Telerik team
Share this question
or