Git Product home page Git Product logo

react-imgpro's Introduction

This project is no longer maintained.

react-imgpro

Build Status status status status yarn

Image Processing Component for React

Introduction

react-imgpro is a image processing component for React. This component process an image with filters supplied as props and returns a base64 image.

Example

const mix = {
    color: 'mistyrose',
    amount: 10
}

class App extends React.Component {
  state = { src: '', err: null }
  render() {
    return (
      <ProcessImage
        image='http://365.unsplash.com/assets/paul-jarvis-9530891001e7f4ccfcef9f3d7a2afecd.jpg'
        colors={{
          mix
        }}
        resize={{ width: 500, height: 500, mode: 'bilinear' }}
        processedImage={(src, err) => this.setState({ src, err, })}
      />     
    )
  }
}

Motivation

I was working on a project last month which involved a lot of image processing and I'd to rely on third party libraries. But before using them directly, I'd to learn different concepts in gl (shaders) and then try to implement them in React. The difficult part was not learning but it was the verbosity, boilerplate code and redundancy introduced by the libraries in the codebase. It was getting difficult to organise all the things 😞

So I wanted a layer of abstraction which would make it easy to manipulate the colors of the image, applying filters and gl shaders efficiently with ease. And React's component based model was perfect for hiding all the implementation details in a component πŸ˜„

Demo

Install

npm install react-imgpro

This also depends on react so make sure you've installed it.

OR

The UMD build is also available via jsDelivr.

<script src="https://cdn.jsdelivr.net/npm/react@16/umd/react.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/react-imgpro@1/build/main.js"></script>

Usage

import React from 'react';
import ProcessImage from 'react-imgpro';

class App extends React.Component {
  state = {
    src: '',
    err: null
  }
  
  render() {
    return (
      <ProcessImage
        image='http://365.unsplash.com/assets/paul-jarvis-9530891001e7f4ccfcef9f3d7a2afecd.jpg'
        resize={{ width: 500, height: 500 }}
        colors={{
          mix: {
            color: 'mistyrose',
            amount: 20
          }
        }}
        processedImage={(src, err) => this.setState({ src, err})}
      />
    )
  }
}

Documentation

See the detailed documentation here.

SSR support ?

Yes, react-imgpro supports SSR.

Contributing

Contributing guide.

Extra resources

If you want to use blenders, plugins and perform event based calculations, try CamanJS.

License

MIT

Sponsor

react-imgpro's People

Contributors

lukasdrgon avatar nitin42 avatar olyvar avatar sunshine168 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-imgpro's Issues

how can i rotate image without width and height resize?

my code
<ProcessImage image={imageSrc} resize={{ width: 400 }} rotate={{ degree: 90 * this.state.rotate }} processedImage={(src, err) => this.setState({ src, err})} />
when the degree is 90 or 180,origin image's width would be current image's height.
I noticed that api doc
rotate
rotate the image
Example -

<ProcessImage image={image} rotate={{ degree: 75, mode: 'bilinear' }}
Optionally, a resize mode can be passed. If false is passed as the second parameter, the image width and height will not be resized.

But i do not kown how to pass the parameter, can you give me a example??

Very slow

Is it possible that we update the libs?

When i render the img, and i log the the the src - (base64) - it is there, but not rendered. After a long time, the console show me again the log with the base64 and than it is rendered...?

What can i do?

ProcessImage doesn't seem to rerender

When we run this sample code, both Images are initially set to "Scott". The "Original Image" then quickly changes to the image loaded in from the database, but the "New Image" (the ProcessImage) stays as "Scott". (It also doesn't change the brightness of the image, and processedImage never seems to kick off)
We have tried this with storage={false} also and it didn't change the results.

`

import React, {Component} from 'react';
import './App.css';
import ProcessImage from 'react-imgpro'
import Scott from './assets/images/Scott-Happy.jpg'

class App extends Component {
    constructor(props) {
        super(props)
        this.state = {
            originalImage: Scott,
            src: '',
            err: null,
            photos: [],
            retrievePhotosLoading: false,
            loadedImage: Scott,
        }
    }

    async componentDidMount() {
        try {
            const photosRetrieved = await fetch('https://localhost:8080/api/v1/images/ASDF')
            const photosJson = await photosRetrieved.json()
            this.setState({
                photos: photosJson,
                getPhotoDataComplete: true,
                loadedImage: window.atob(photosJson[0].photoData)
            })
        } catch (error) {
            console.log(error)
        }
    }

    render() {
        return (
            <div>
                <h1>This is our imgPro Test Playground</h1>
                <br/><br/>

                <b>Original Image</b>
                <br/>
                <img src={this.state.loadedImage} alt="Scott is REALLY happy"/>
                <br/><br/>
                <b>New Image:</b>
                <br/>
                <ProcessImage
                    image={this.state.loadedImage}
                    brightness={.8}
                    // processedImage={(src, err) => this.setState({src, err,})}
                />
            </div>
        );
    }
}

export default App;

`

Confusion

hi
i have a confusion in using this lib which we cant update the component by change the some options dynamic?

if i miss something, please point me out , think you !!!
i create a sanBox
Edit k04q34zl35

component will re-render by size changed but did not work by other config


btw the the work import cdn file break by china GFW emmm , so it can be set in config will be flexible

multiple sizes of the same image

Great piece of software!
How would I go about making three (... more) copies of different sizes of the same image? Before, for example, an s3 upload ... ?
Thanks!

invariant violation: view config getter callback for ocomponent 'img' must be a function

Hi please find my below code

import React, { Component } from 'react';
import ProcessImage from 'react-imgpro';
import { IMG_APP_LOGO } from '../images';

class CamFilter extends React.Component {
state = {
src: '',
err: null
}

render() {
  return (
    <ProcessImage
      image={IMG_APP_LOGO}
      resize={{ width: 500, height: 500 }}
      colors={{
        mix: {
          color: 'mistyrose',
          amount: 20
        }
      }}
      processedImage={(src, err) => this.setState({ src, err})}
    />
  )
}

}

export default CamFilter;

i am getting following error
invariant violation: view config getter callback for component 'img' must be a function

How can i update props on button click

Here is my code and i want to change greyscale to true on button click using function that.editType('greyscale')

import React, { Component } from 'react';
import ProcessImage from 'react-imgpro';
import styles from '../style.scss';

const style = {
container:{
display:'flex',
alignItems:'center',
height:'100%'
},
itemContainer:{
left:0
},
bgImgaesContainer:{
width:'100%',
left:0
}
}

class PostEditImage extends Component{

state = {
src: '',
err: null,
greyscale:false
}

editType=(type)=>{
switch(type){
case 'greyscale':
this.setState({greyscale:true})
break;
}
}

render(){
var w = window.innerWidth;
var that =this;
return(


<ProcessImage
image={'http://365.unsplash.com/assets/paul-jarvis-9530891001e7f4ccfcef9f3d7a2afecd.jpg'}
resize={{ width: w}}
greyscale={that.state.greyscale}

  />
  <div style={style.bgImgaesContainer} className={`${styles.bgImgaesContainer} ${styles.width90}`}>
    <div style={style.itemContainer} className={styles.itemContainer}>
          <div onClick={(e)=>that.editType('greyscale')} style={{backgroundColor:'#000'}} className={`${styles.item} ${styles.item1}`}>
            greyscale
          </div>
          <div onClick={(e)=>that.editType('greyscale')} style={{backgroundColor:'#a52a2a'}} className={`${styles.item} ${styles.item2}`}>
            2
          </div>
          <div onClick={(e)=>that.editType()} style={{backgroundColor:'#d2691e'}} className={`${styles.item} ${styles.item3}`}>
            3
          </div>
          <div onClick={(e)=>that.editType()} style={{backgroundColor:'#0000ff'}} className={`${styles.item} ${styles.item4}`}>
            4
          </div>
          <div onClick={(e)=>that.editType()} style={{backgroundColor:'#e9967a'}} className={`${styles.item} ${styles.item5}`}>
            5
          </div>
          <div onClick={(e)=>that.editType()} style={{backgroundColor:'#556b2f'}} className={`${styles.item} ${styles.item5}`}>
            6
          </div>
          <div onClick={(e)=>that.editType()} style={{backgroundColor:'#cd5c5c'}} className={`${styles.item} ${styles.item5}`}>
            7
          </div>
          <div onClick={(e)=>that.editType()} style={{backgroundColor:'#800000'}} className={`${styles.item} ${styles.item5}`}>
            8
          </div>
          <div onClick={(e)=>that.editType()} style={{backgroundColor:'#f96332'}} className={`${styles.item} ${styles.item5}`}>
            9
          </div>
          <div onClick={(e)=>that.editType()} style={{backgroundColor:'#c0c0c0'}} className={`${styles.item} ${styles.item5}`}>
            7
          </div>
          <div onClick={(e)=>that.editType()} style={{backgroundColor:'#4682b4'}} className={`${styles.item} ${styles.item5}`}>
            8
          </div>
          <div onClick={(e)=>that.editType()} style={{backgroundColor:'#006400'}} className={`${styles.item} ${styles.item5}`}>
            9
          </div>
    </div>
  </div>  
</div>

)
}
};

export default PostEditImage;

Access img ref/reference

Hello!

I need to access reference of the rendered img component. It is impossible right now.

We have 2 options:

  • Add new prop innerRef/imgRef/etc which will be passed to img component
  • Use React 16 forwardRef API to pass ref to the rendered img component

What do you think? Since this component is rendering img component directly, I think the second solution will be more appropriate.

Can't use Base64 as source

It would be really handy to be able to use base64 as the image instead of a URL... do you know of a way to do this?

This looks amazing and I'd really love to be able to use it.

Thanks.

Blob support?

Does this library support receiving images as blobs?

Display the same image on render

While rendering, the ProcessImage component has a strange behavior. It displays the same image on a map loop during a second. As if it populates each item with the first image loaded and processed and then only displays the correct image.
On a classical <img> tag, I don't have this behavior.

render() {
    const { products } = this.state;
    return (
      <div className="page">
        {products.map(product => 
          <div className="productGrid" key={product.objectID}>
            <h1>{product.title}</h1>  
            <ProcessImage
              image={product.imageUrl}
              resize={{ width: 200, height: 200 }}
               />
            <p>{product.description}</p>
            <p>Price: {product.price}</p>
          </div>
        )}
      </div>
    );
  }

Not working on react-native

package.json :
"react": "16.3.1",
"react-imgpro": "^1.3.9",
"react-native": "0.55.4",

I am getting the following error when trying to import this library:

**A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:

Invalid:
{ presets: [{option: value}] }
Valid:
{ presets: [['presetName', {option: value}]] }**

Issues loading image on https domain.

I'm receiving the error:

Mixed Content: The page at 'blob:https://mysecuredomain.com/053ee38d-3f6c-4498-8b44-78164f266038' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://cors-anywhere.herokuapp.com/https://mycdn.com/1535123777.png'. This request has been blocked; the content must be served over HTTPS.

This issue seems to be caused by using cors-anywhere on http on an https domain. Is there somewhere to configure cors-anywhere to use https?

I believe this is also causing jimp to throw an exception:

Uncaught Error: Uncaught, unspecified "error" event. ([object ProgressEvent])
at Jimp.EventEmitter.emit (jimp.min.js:27)
at Jimp.emitMulti (jimp.min.js:27)
at Jimp.emitError (jimp.min.js:27)
at jimp.min.js:27

Thanks for your time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.