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

TypeError: options.imageSource.saveToFile is not a function #13

Closed lord-zeus closed 5 years ago

lord-zeus commented 5 years ago

passing the image and its not finding the saveToFile function

TypeError: options.imageSource.saveToFile is not a function

PeterStaev commented 5 years ago

Problem is the same as your other issue. Make sure you are using the plugin as explained in readme and as demonstrated in the demo app in this repo.

lord-zeus commented 5 years ago
        `const photoEditor = new PhotoEditor();
           let imageSource = fromFileOrResource('~/assets/images/logo.png');

         console.log("ORIG IMAGE: ", imageSource.height, imageSource.width)

          photoEditor.editPhoto({
                imageSource: imageSource.android, // originalImage.imageSource,

          }).then((newImage) => {
               console.log("NEW IMAGE: ", newImage.height, newImage.width)
           }).catch((e) => {
             `   console.error(e);

            });`

this is my code

and the console is : 'ORIG IMAGE: ' 252 269 TypeError: options.imageSource.saveToFile is not a function

PeterStaev commented 5 years ago

Hey @lord-zeus , Per the docs and demos you should send the image source to the plugin not the native object like you do. So the correct code should be something like:

const photoEditor = new PhotoEditor();
let imageSource = fromFileOrResource('~/assets/images/logo.png');

console.log("ORIG IMAGE: ", imageSource.height, imageSource.width)

photoEditor.editPhoto({
    imageSource,            
}).then((newImage) => {
    console.log("NEW IMAGE: ", newImage.height, newImage.width)
}).catch((e) => {
    console.error(e);
});
max-pro commented 5 years ago

fromFileOrResource function is not defined. what we need to import

PeterStaev commented 5 years ago

@max-pro , it is from the image-source nativescript module: https://docs.nativescript.org/api-reference/modules/_image_source_

PeterStaev commented 5 years ago

No further response so closing this one for now. In case you still have problems, please provide more details.

max-pro commented 5 years ago

How to save image. Save function is undefined