How to use smartcrop - 10 common examples

To help you get started, we’ve selected a few smartcrop examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github area17 / twill / frontend / js / components / MediaField.vue View on Github external
} else if (ratio >= 1) { // "landscape" or square crop
              cropHeight = Math.floor(Math.min(width / ratio, height))
              cropWidth = Math.floor(cropHeight * ratio)
            }

            let crop = {
              x: 0,
              y: 0,
              width: cropWidth,
              height: cropHeight
            }

            // Convert crop for original img values
            crop = cropConversion(crop, this.naturalDim, this.originalDim)

            smarcrops.push(smartCrop.crop(this.img, { width: crop.width, height: crop.height, minScale: 1.0 }))

            const x = Math.floor(center.x - cropWidth / 2)
            const y = Math.floor(center.y - cropHeight / 2)

            defaultCrops[cropVariant] = {}
            defaultCrops[cropVariant].name = this.allCrops[this.cropContext][cropVariant][0].name || cropVariant
            defaultCrops[cropVariant].x = x
            defaultCrops[cropVariant].y = y
            defaultCrops[cropVariant].width = cropWidth
            defaultCrops[cropVariant].height = cropHeight
          }

          Promise.all(smarcrops).then((values) => {
            let index = 0
            values.forEach((value) => {
              const topCrop = {
github mertyildiran / Dermatron / client / views / visits / form_visits.js View on Github external
<figcaption><p>' + DIAGNOSES_DICT_SWAP[element.diagnosis[0].Id] + '</p></figcaption> \
                        ';
                    });
                    if (threeSample != '') {
                        $('div#dermquest-suggestions').html(suggestionsDermQuest);
                        $('figure').show('slow');
                    }
                });

                var getPixels = require("get-pixels");
                var smartcrop = require('smartcrop');
                var Clipper = require('image-clipper');

                var img = new Image();
                img.src = data;
                smartcrop.crop(img, {width: 64, height: 64}).then(function(smart){
                  Clipper(data, function() {
                        this.crop(smart.topCrop.x, smart.topCrop.y, smart.topCrop.height, smart.topCrop.width)
                        .resize(64, 64)
                        .quality(100)
                        .toDataURL(function(dataUrl) {
                            //console.log('cropped!');
                            //$('div#capturedImage img').attr('src', dataUrl);

                            getPixels(dataUrl, function(err, pixels) {

                                var matrix = []
                        		var count = 0
                        		var rgbaIndex = 0
                        		var currentObj = {}

                        		Object.keys(pixels.data).forEach((k, i) =&gt; {
github scaleflex / filerobot-uploader / projects / react-plugin / components / UploadImagesTab / PreUploadProcess.js View on Github external
y: face.y / scale,
            width: face.width / scale,
            height: face.height / scale,
            weight: 1.0
          });
        }

        src.delete();
        gray.delete();
        faceCascade.delete();
        faces.delete();
        result.push(nextOptions);

        const image = self._previewBox.children[index].children[0];

        smartcrop.crop(image, nextOptions, (result) => {
          self.draw(result, image);
        });
      });
    });
github digiwombat / WorldMuncher / lib / functions.js View on Github external
function characterCrop()
{
	if (!img) return;
	var options = {
		width: 175,
		height: 180,
		minScale: 1.0,
		ruleOfThirds: true
	};

	smartcrop.crop(img, options).then(function(result){
		var canvas = document.createElement('canvas');
		canvas.width = result['topCrop']['width'];
		canvas.height = result['topCrop']['height'];
		ctx = canvas.getContext('2d');
		ctx.imageSmoothingEnabled = false;
		ctx.drawImage(img,
					  result['topCrop']['x'], result['topCrop']['y'],
					  result['topCrop']['width'], result['topCrop']['height'],
					  0,0,
					  result['topCrop']['width'], result['topCrop']['height']
					 );
		var HERMITE = new Hermite_class();
		HERMITE.resample_single(canvas, 175, 180, true, function(){return;});

		document.getElementById("person_picture").src = canvas.toDataURL();
		worlddb['people'].filter(function (el) {
github SkalskiP / ILearnMachineLearning.js / src / components / modelViews / ImageLoader.tsx View on Github external
public async drawPredRects() {
        let size = Math.min(this.passiveCanvas.width, this.passiveCanvas.height);
        let imgSize = Math.min(this.img.naturalWidth, this.img.naturalHeight);
        const scale = imgSize/size;

        let smartCropRect = await smartcrop.crop(this.img, { width: imgSize, height: imgSize });
        
        this.predictionsRect = new Rect(
            smartCropRect.topCrop.x / scale,
            smartCropRect.topCrop.y / scale,
            smartCropRect.topCrop.width / scale,
            smartCropRect.topCrop.height / scale
        );

        DrawUtil.shadeEverythingButRect(this.activeCanvas, this.predictionsRect, "rgba(0, 0, 0, 0.7)");
        DrawUtil.drawRect(this.activeCanvas, this.predictionsRect, "rgba(255, 255, 255, 0.5)", 1);
    }
github scaleflex / filerobot-uploader / projects / react-plugin / components / UploadImagesTab / PreUploadProcess.js View on Github external
elements.forEach((wrapper) => {
      const { width, height } = this.state.imagesParams;

      smartcrop.crop(wrapper.children[0], { width, height, minScale: 1 }, (result) => {
        this.draw(result, wrapper.children[0]);
      });

    })
  }
github jwagner / smartcrop-gm / index.js View on Github external
exports.crop = function(img, options, callback) {
  options = options || {};
  options.imageOperations = iop;
  return smartcrop.crop(img, options, callback);
};
github jwagner / smartcrop-sharp / index.js View on Github external
exports.crop = function(img, options, callback) {
  options = options || {};
  options.imageOperations = iop;
  return smartcrop.crop(img, options, callback);
};
github jwagner / smartcrop-sharp / index.js View on Github external
.then(function(data) {
        if (data.length === image.width * image.height * 3) {
          data = rgb2rgba(data);
        }
        if (data.length !== image.width * image.height * 4) {
          throw new Error('unexpected data length ' + data.length);
        }
        return new smartcrop.ImgData(image.width, image.height, data);
      });
  }
github jwagner / smartcrop-gm / index.js View on Github external
.toBuffer('RGBA', function(err, buffer) {
          if (err) return reject(err);
          resolve(new smartcrop.ImgData(image.width, image.height, buffer));
        });
    });

smartcrop

Content aware image cropping.

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis

Popular smartcrop functions

Similar packages