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

image-cutter

v0.0.3

Published

React component for take a square from an image. Usefull for edit profile photo before saving.

Downloads

3

Readme

image-cutter

React.js component to cut an image and generate a square image from it. Useful to edit profile images before saving

Install

npm i image-cutter

https://www.npmjs.com/package/image-cutter

Usage

On your component import:

import  ImageCutter  from  "image-cutter";

Call de component:

<ImageCutter
    image_src = { image_source }
    side = "400"
    callback = { callback_funtion }
    close = { close_function }
    width = "400"
/>

|property| description| |--|--| |image_src| image source like base 64| |side| side size of resulting image | |callback| your function to handling the result. ImageCutter return a object like {base64:base64_string, blob:blob} on the callback funtion param. ejm function myCallback(result_obj){...} |close| your function to what to do after get the result of ImageCutter |width| size of cutter, width and height of <div/> that show the image to cut

note: image_src must be a local source to avoid cross origin constraint. If you want to get the cut from external image first you can get the data through Fetch and take the base64 result then pass it to ImageCutter

Example

   import  React  from  "react";
   import  ImageCutter  from  "image-cutter";
    
   export  default  class  App  extends  React.Component {
       constructor(props) {
	   super(props);
	   this.callback  =  this.callback.bind(this);
	   this.click  =  this.click.bind(this);
	   this.state  = {
		    img_src:"data:image/jpeg;base64,/9j/.....",
		    img_rslt: "",
			image_cutter:  false
	   };
   }
    callback(rslt) {
	    console.log(rslt);
	    this.setState({ img_rslt:  rslt.base64 });
    }
    click() {
	    this.setState({ image_cutter:  !this.state.image_cutter });
    }
    render() {
	    return (
		    <div  className="App">
				<img
				    src={this.state.img_src}
				    onClick={this.click}
			    />
			    <p>click/tap on image, select and see the result below.</p>
			    {(() => {
				    if (this.state.image_cutter) {
					    return (
						    <ImageCutter
							    image_src={this.state.img_src}
							    side="400"
							    callback={this.callback}
							    close={this.click}
							    width="400"
						    />
					    );
				    }
				    return  null;
				})()}
				<img  src={this.state.img_rslt} alt=""  />
		    </div>
	    );
    }
}

watch it working on sandbox: https://codesandbox.io/s/image-cutter-0v2he?file=/src/App.js:0-41414

How it work?

In depth is the html5 Canvas API that does the job. The source image to cut is instantiated in a javacript Image object after a Canvas api is instantiated with the image object before created and the square image is drawn on the canvas, at the end, the result is returned using the api function Canvas to get base64 and blob.

html, css and javascript main idea: https://codepen.io/ivanot/pen/GRpYVxm

Style

this are the css class, feel free to overwrite. "ic" is for image cutter

.ic-scroll{
  ...
}
.ic-scroll > canvas{
  ...
}
.ic-scroll::-webkit-scrollbar {
  ...
}
.ic-scroll::-webkit-scrollbar-button {
  ...
}
.ic-scroll::-webkit-scrollbar-thumb {
  ...
}
.ic-scroll::-webkit-scrollbar-track {
 ...
}

.ic-scroll::-webkit-scrollbar-corner {
  ...
}
.ic-button{
  ...
}
.ic-buttons{
  ...
}
.ic-background{
 ...
}