Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM document #56

Open
360disrupt opened this issue Nov 5, 2018 · 0 comments
Open

DOM document #56

360disrupt opened this issue Nov 5, 2018 · 0 comments

Comments

@360disrupt
Copy link

I would like to use node-vibrant is there a shim for document planned? https://github.com/akfish/node-vibrant/search?q=document&unscoped_q=document
Currently, I'm running into the error:

Can't find variable: document

Code example:

import { Component, OnInit } from '@angular/core';
require("nativescript-nodeify")
const Vibrant = require('node-vibrant');
import * as camera from "nativescript-camera";
import { fromAsset } from "image-source";
import { knownFolders, path} from "file-system"
const VERSION = "v2"

@Component({
    selector: 'ns-snapshot',
    templateUrl: './snapshot.component.html',
    styleUrls: ['./snapshot.component.css'],
    moduleId: module.id,
})
export class SnapshotComponent implements OnInit {
    result: string;
    image: any = null;
    version = VERSION;
    
    constructor() { }
    
    ngOnInit() {
        console.log("checking camera")
        camera.requestPermissions()
    }

    getColor(imgSrc) {
        console.log("filepath", imgSrc)
        console.log("Analyzing color");
        Vibrant.from(imgSrc).getPalette((err, palette) => {
            console.log("err", err);
            console.log("palette", palette);
            this.result = palette.toString();
        })
    }

    takeSnapshot() {
        console.log("taking snapshot" + VERSION)
        const cameraOptions = { saveToGallery: false }
        camera.takePicture(cameraOptions)
            .then( (imageAsset) => {
                fromAsset(imageAsset)
                    .then((imageSource) => {
                        const folder = knownFolders.temp();
                        const filePath = path.join(folder.path, "test" + ".png");
                        console.log('saving to', filePath)
                        if (imageSource.saveToFile(filePath, "png", 90)) {
                            this.getColor(filePath);
                        }
                    });
            }).catch( (err) => {
                console.log("Error -> " + err.message);
            });
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant