Esempio n. 1
0
    createResized(filePath, options) {
        const suffix = options.suffix || 'resized';
        const interpolation = options.interpolation || 'linear';
        const format = options.format || 'png';
        const dstPath = this.getPathWithoutExtension(filePath) + `_${suffix}.png`;

        return lwip
            .openAsync(filePath)
            .then(image => {
                const width = image.width();
                const height = image.height();
                const aspectRatio = width / height;

                let resizeWidth = width;
                let resizeHeight = height;

                if (resizeWidth > options.width) {
                    resizeWidth = options.width;
                    resizeHeight = resizeWidth / aspectRatio;
                } else if (resizeHeight > options.height) {
                    resizeHeight = options.height;
                    resizeWidth = resizeHeight * aspectRatio;
                }

                return image.resizeAsync(resizeWidth, resizeHeight, interpolation);
            })
            .then(resizedImage => resizedImage.writeFileAsync(dstPath, format))
            .then(() => dstPath);
    };
Esempio n. 2
0
    createCover(filePath, options) {
        const suffix = options.suffix || 'cover';
        const interpolation = options.interpolation || 'linear';
        const format = options.format || 'png';
        const dstPath = this.getPathWithoutExtension(filePath) + `_${suffix}.png`;

        return lwip
            .openAsync(filePath)
            .then(image => image.coverAsync(options.width, options.height, interpolation))
            .then(resizedImage => resizedImage.writeFileAsync(dstPath, format))
            .then(() => dstPath);
    }