PHP Classes

File: toastui/src/js/command/loadImage.js

Recommend this page to a friend!
  Classes of Mark de Leon  >  PHP Document Scanner using SANE or eSCL AirPrint  >  toastui/src/js/command/loadImage.js  >  Download  
File: toastui/src/js/command/loadImage.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP Document Scanner using SANE or eSCL AirPrint
Web interface to scan printed documents
Author: By
Last change:
Date: 1 year ago
Size: 1,826 bytes
 

Contents

Class file image Download
/**
 * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>
 * @fileoverview Load a background (main) image
 */
import commandFactory from '../factory/command';
import consts from '../consts';

const {componentNames, commandNames} = consts;
const {IMAGE_LOADER} = componentNames;

const command = {
    name: commandNames.LOAD_IMAGE,

    /**
     * Load a background (main) image
     * @param {Graphics} graphics - Graphics instance
     * @param {string} imageName - Image name
     * @param {string} imgUrl - Image Url
     * @returns {Promise}
     */
    execute(graphics, imageName, imgUrl) {
        const loader = graphics.getComponent(IMAGE_LOADER);
        const prevImage = loader.getCanvasImage();
        const prevImageWidth = prevImage ? prevImage.width : 0;
        const prevImageHeight = prevImage ? prevImage.height : 0;
        const objects = graphics.removeAll(true).filter(objectItem => objectItem.type !== 'cropzone');

        objects.forEach(objectItem => {
            objectItem.evented = true;
        });

        this.undoData = {
            name: loader.getImageName(),
            image: prevImage,
            objects
        };

        return loader.load(imageName, imgUrl).then(newImage => ({
            oldWidth: prevImageWidth,
            oldHeight: prevImageHeight,
            newWidth: newImage.width,
            newHeight: newImage.height
        }));
    },

    /**
     * @param {Graphics} graphics - Graphics instance
     * @returns {Promise}
     */
    undo(graphics) {
        const loader = graphics.getComponent(IMAGE_LOADER);
        const {objects, name, image} = this.undoData;

        graphics.removeAll(true);
        graphics.add(objects);

        return loader.load(name, image);
    }
};

commandFactory.register(command);

module.exports = command;
For more information send a message to info at phpclasses dot org.