npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

opticrop-node

v1.0.0

Published

Optimized thumbnail-generation algorithm (edge-maximizing crop & resize)

Downloads

10

Readme

opticrop-node

node.js port of jueseph/Opticrop

Detect the most interesting part of picture and crops it

tested on node v7.7.4

Description

Unlike most cropping routines out there, Opticrop uses edge-detection to find the most “interesting” part of the image to crop, so you won’t get a useless thumbnail just because the top-left corner of your image happened to be a big patch of featureless sky.

Limitations

Opticrop was written to be smarter than easily available alternatives, but because the strategy is relatively simple, it still makes the “wrong” crop on certain images.

read more

Example #1 - crops original image just fine example1

Example #2 - the result is perfect example2

Example #3 - result is not as good as you probably expected example3

Installation

First install graphicsmagick and dev version od GD2 (more info here)

on Debian/Ubuntu

sudo apt-get install graphicsmagick
sudo apt-get install libgd2-xpm-dev
OR
sudo apt-get install libgd2-dev # libgd
npm install opticrop-node

On RHEL/CentOS

$ sudo yum install gd-devel
npm install opticrop-node

on Mac OS/X

brew install graphicsmagick
brew install pkg-config gd
npm install opticrop-node

Will not build on Windows!

Example

cropTo returns bluebird Promise if callback param is not passed down

const Opticrop = require('opticrop-node').Opticrop;
const opticrop = new Opticrop;
opticrop
  .setImage(inFile)
  .setWidth(100)
  .setHeight(100)
  .cropTo(outFile)
  .then(() => {
    console.log('crop is done')
  })
  .catch((err) => {
    console.log("Error", err);
  });

or it accepts a callback as last argument

const Opticrop = require('opticrop-node').Opticrop;
const opticrop = new Opticrop;
opticrop
.setImage('./images/example.jpg')
  .setWidth(100)
  .setHeight(100)
  .cropTo('./images/cropped_example.jpg', (err, data) => {
    console.log("Cropping done", err, data);
  });

Test

Following command will crop example images and save as images/cropped_example.(gif|jpg|png)

node test.js

You also can check if there are memory leaks

TEST_MEMORY=1 node test.js

Version History

1.0.0

Rewritten in TypeScript

0.1.2

Updated installation instructions 0.1.1

Cropping speed was increased by 3 times due to replacing of mikolalysenko/get-pixels with mikesmullin/node-gd

0.1.0

Ported version of jueseph/Opticrop