Git Product home page Git Product logo

waifu2x-node's Introduction

Waifu2x Converter for NodeJS

NodeJS bindings / wrapper for using libw2xc from waifu2x-converter-cpp

Used to upscale photos or Anime-style art using convolutional neural networks.

Usage

This module currently only supports GNU/Linux and Windows.

Prerequisites

This project requires node-gyp to build, make sure it is installed using npm install -g node-gyp

Windows x64

Make sure you have node-gyp setup correctly. You'll need Visual Studio 2015 or later installed to compile the source. See https://www.npmjs.com/package/node-gyp#on-windows for more info.

Dependencies are installed automatically but require 7z to extract the binaries, make sure it is installed at the default install path C:\Program Files\7-Zip\7z.exe

The install scripts should install all dependencies automatically so no additional setup is required.

Linux

Install the dependencies listed below.

Make sure the you install it in one of the linker's search directories. It should be by default if you use your package manager or follow the build instructions below.

OpenCV

Install OpenCV using your distrobution's package manager.

On arch you'll use pacman -S opencv

waifu2x-converter-cpp

Installation

Install using npm

npm install waifu2x-node

Synchronous Examples

Upscaling a file

import { W2XCJS, DEFAULT_MODELS_DIR } from 'waifu2x-node';

const converter = new W2XCJS();

const err = converter.loadModels(DEFAULT_MODELS_DIR);

if (!err) {
    const conv_err = converter.convertFile("in.png", "out.webp");
    if (!err) {
        console.log('File converted successfully');
    }
}

Upscale a buffer

import { W2XCJS, DEFAULT_MODELS_DIR } from 'waifu2x-node';
import fs from 'fs';

const converter = new W2XCJS();

const err = converter.loadModels(DEFAULT_MODELS_DIR);

if (!err) {
    const input_buffer = fs.readFileSync("in.png");
    const output_buffer = converter.convertBuffer(input_buffer, '.JPG'); // second parameter is the file extension to encode to.
    fs.writeFileSync("out.jpg", output_buffer);
}

Asynchronous examples

Asynchronous functions only work on GPU processor types due to instabilities on the CPU

Upscaling using callbacks

import { W2XCJS, DEFAULT_MODELS_DIR } from 'waifu2x-node';
import fs from 'fs';

const converter = new W2XCJS();

const err = converter.loadModels(DEFAULT_MODELS_DIR); // model loading is synchronous

if (!err) {
    fs.readFile("in.png", (err, input_buffer) => {
        if (err) throw err;
        converter.convertBufferAsync(input_buffer, '.WEBP', { /* AsyncOptions */ }, dst_buffer => {
            fs.writeFile("out.webp", dst_buffer, err => {
                if (err) throw err;
            })
        })
    });
}

Upscaling using promises

The library provides a wrapper class for using promises

import { W2XCJS, DEFAULT_MODELS_DIR, W2XCJSPromises } from 'waifu2x-node';
import fs from 'fs';

const promises = new W2XCJSPromises(new W2XCJS());

const err = promises.converter.loadModels(DEFAULT_MODELS_DIR); // model loading is synchronous

if (!err) {
    (async () => {
        const input_buffer = await fs.promises.readFile("in.png");
        const dst_buffer = await promises.convertBuffer(input_buffer, '.WEBP', { /* AsyncOptions */ });
        await fs.promises.writeFile("out.webp", dst_buffer);
    })();
}

Asynchronous convert options (AsyncOptions)

Abstract of the library source for reference, you could also generate the documentation for more detailed overview.

interface AsyncOptions {
    // encoding options for destination buffer.
    imwrite_params: ImwriteParams;
    // denoising options (number value from -1 to 3 where -1 is no denoising)
    denoise_level: DenoiseLevel;
    // Scale factor.
    scale: number;
}
interface ImwriteParams {
    // quality factor for webp and jpeg from 0 to 101 where 101 is lossless.
    webp_quality?: number;
    jpeg_quality?: number;
    // compression factor for png from 0 to 9 where 9 is smallest size and longest time.
    png_compression?: number;
}

Documentation

Documentation is generated using TypeDoc, run npm run docs:build to build the documentation and npm run docs:serve to serve a local copy of the documentation.

waifu2x-node's People

Contributors

dependabot[bot] avatar wykerd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

waifu2x-node's Issues

Hi can you help me with this?

Hi,
I have been trying to install this for so long but i am still unable to after trying for so many hours. The error im facing is this:
/home/agam/.cache/node-gyp/10.24.1/include/node/v8.h:4013:43: note: declared here
_UNUSED_RESULT MaybeLocal Call(Local context,
^~~~
CXX(target) Release/obj.target/w2xcjs/src/conv.o
SOLINK_MODULE(target) Release/obj.target/w2xcjs.node
/usr/bin/ld: cannot find -lw2xc
collect2: error: ld returned 1 exit status
w2xcjs.target.mk:139: recipe for target 'Release/obj.target/w2xcjs.node' failed
make: *** [Release/obj.target/w2xcjs.node] Error 1
make: Leaving directory '/home/agam/flash_images/node_modules/waifu2x-node/build'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.