PeterStaev / nativescript-photo-editor

🎨 Easily edit an image in your NativeScript app (crop, draw, etc)
Apache License 2.0
47 stars 15 forks source link

Usage in plain Javascript #20

Closed marcelbonfim182 closed 5 years ago

marcelbonfim182 commented 5 years ago

Hello, can you make a usage code available in "pure javascript" (nativescript plain)? I Try to use the code bellow, but in the console apear: TypeError: "PhotoEditor is not a constructor":

var photoEditor = new PhotoEditor();

const folder = fileSystemModule.knownFolders.currentApp(); const path = fileSystemModule.path.join(folder.path, "photos/20190212_232246.jpg"); const imageFromLocalFile = imageSourceModule.fromFile(path); console.log("ORIG IMAGE: ", imageFromLocalFile.height, imageFromLocalFile.width);

photoEditor.editPhoto({
    imageSource: imageFromLocalFile, // originalImage.imageSource,
    hiddenControls: [
        // PhotoEditorControl.Save,
        // PhotoEditorControl.Clear,
        // PhotoEditorControl.Draw,
        // PhotoEditorControl.Text,
    ],
}).then(function (newImage) {
    console.log("NEW IMAGE: ", newImage.height, newImage.width);
    alert(newImage);
}).catch(function (e) {
    console.error(e);
});
marcelbonfim182 commented 5 years ago

It worked here! I found the issue!

`const PhotoEditor = require ("nativescript-photo-editor").PhotoEditor; const PhotoEditorControl = require ("nativescript-photo-editor"); const imageSourceModule = require("tns-core-modules/image-source"); const fileSystemModule = require("tns-core-modules/file-system");

exports.editImage = function(args) {

var photoEditor = new PhotoEditor();

const folder = fileSystemModule.knownFolders.currentApp(); const path = fileSystemModule.path.join(folder.path, "photos/20190212_232246.jpg"); const imageFromLocalFile = imageSourceModule.fromFile(path); console.log("ORIG IMAGE: ", imageFromLocalFile.height, imageFromLocalFile.width);

photoEditor.editPhoto({
    imageSource: imageFromLocalFile, // originalImage.imageSource,
    hiddenControls: [
        // PhotoEditorControl.Save,
        // PhotoEditorControl.Clear,
        // PhotoEditorControl.Draw,
        // PhotoEditorControl.Text,
    ],
}).then(function (newImage) {
    console.log("NEW IMAGE: ", newImage.height, newImage.width);
    alert(newImage);
}).catch(function (e) {
    console.error(e);
});

} `