Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Support for cropping imageB #4

Closed
koola opened this issue Nov 27, 2014 · 3 comments
Closed

Support for cropping imageB #4

koola opened this issue Nov 27, 2014 · 3 comments

Comments

@koola
Copy link

koola commented Nov 27, 2014

Would be great if blinkdiff supported image cropping so that for example a small image could be compared with a cropped region of a larger image like a screenshot.

Something like:

function BlinkDiff (options) {

    this._imageCropRegion = options.imageCropRegion || {};

}
    run: function (fn) { 
        ...
            }.bind(this)).then(function (imageB) {
                this._imageB = imageB;

                if (Object.keys(this._imageCropRegion).length > 0) {
                    this._crop(this._imageB, this._imageCropRegion);
                }

                this._clip(this._imageA, this._imageB);
      ...
    },
    /**
     * Crops the source image to the bounds of rect
     *
     * @private
     * @method _crop
     * @param {PNGImage} image Source image
     * @param {object} rect Values for rect
     * @param (int} rect.left Left value of rect
     * @param (int} rect.top Top value of rect
     * @param (int} rect.width Width value of rect
     * @param (int} rect.height Height value of rect
     */
    _crop: function (image, rect) {

        if ((rect.left + rect.width) <= image.getWidth() && (rect.top + rect.height) <= image.getHeight()) {

            this.log("Cropping from " + rect.left + "," + rect.top + " by " + rect.width + " x " + rect.height);

            image.clip(rect.left, rect.top, rect.width, rect.height);
        }
    },
marcelerz pushed a commit that referenced this issue Nov 28, 2014
@marcelerz
Copy link
Contributor

I just pushed the cropping feature. Now, you can crop each of the images by supplying a crop-object. The properties of these objects are:

  • x - X coordinate (Left)
  • y - Y coordinate (Top)
  • width - Width of image
  • height - Height of image

Note that the x and y coordinates are different to your suggested left and top property names.
You can also leave some of the values off. Then, they will be calculated according to some rules.

Thank you again for these great suggestions. I really appreciate it.

I still work on two more features, and I will publish the code then to NPM. I will keep you posted.

@koola
Copy link
Author

koola commented Nov 28, 2014

That's awesome! Thanks a lot for implementing this.

@koola koola closed this as completed Nov 28, 2014
@marcelerz
Copy link
Contributor

No problem. I thank you! 👍
Also, I just pushed it to NPM.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants