Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotate image #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

tejitak
Copy link

@tejitak tejitak commented Mar 17, 2015

It is an enhancement that image component accepts a specified rotate (angle) value.
Usages is a just setting rotate as a prop like below.

e.g. jsx in css-layout example
<Image src='http://lorempixel.com/360/420/cats/1/' style={this.getImageStyle()} fadeIn={true} rotate={20} />

I need this capability to implement a rotating jump action in a simple game by using React state.
e.g. <Image src="..." rotate={this.state.rotate} />

@Mickey-
Copy link

Mickey- commented May 30, 2015

is there any method to scale image instead of using html?

    <img src="xxx-400x200.png"  style="width:200px;height:100px" />

@tejitak
Copy link
Author

tejitak commented Jun 1, 2015

Hi @Mickey- ,
You can specify the image size in React component.
e.g. (modify on "examples/css-layout/app.js")

  render: function () {
    return (
      <Surface top={0} left={0} width={400} height={400} enableCSSLayout={true}>
            <Image src='http://lorempixel.com/360/420/cats/1/' style={this.getImageStyle()} fadeIn={true} rotate={20} />
      </Surface>
    );
  },

  getImageStyle: function () {
    return {
      width: 200,
      height: 100
    };
  },

The image size will be dynamically changed according to the returned value of getImageStyle() in this case.

@Mickey-
Copy link

Mickey- commented Jun 1, 2015

Sorry,Maybe I didn't speak clearly @tejitak
For example, when I use

    <Image src='https://d2eip9sf3oo6c2.cloudfront.net/series/covers/000/000/005/full/react_flux_series_banner_2.png?1404147531' style={this.getImageStyle()}  />

I get
image

But what I need is scale image, not crop it,just like
image

What should I do? whatever, thank you very much: )

P.S. Where can I get full documentation?

@tejitak
Copy link
Author

tejitak commented Jun 5, 2015

Hi @Mickey- ,
I think It can not be done without any code changes.

I modified the code and added an attributed 'imageScale' in my new forked branch. Please try the following procedure.

  1. apply the following changes to your repository
    tejitak@bd713f1
  2. use 'imageScale={true}' on image component
    e.g.
    <Image src='https://d2eip9sf3oo6c2.cloudfront.net/series/covers/000/000/005/full/react_flux_series_banner_2.png?1404147531' style={this.getImageStyle()} fadeIn={true} imageScale={true} />

Note that it is just a temporary patch and not fully tested.
Thanks

@adamellsworth
Copy link

+1 on this.

Ideally it'd be great to just pass the drawImage properties down via <Image sx={0} sy={10} /> etc:

sx, sy, swidth, sheight, dx, dy, dwidth, dheight

@adamellsworth
Copy link

@tejitak does the drawImage event support appending options (focusPoint) like that? I can't find docs on the function where it accepts the extra object after dHeight.

@tejitak
Copy link
Author

tejitak commented Jul 3, 2015

Hi @adamellsworth ,
Thank you for your comment. Passing these properties looks nice feature.

Regarding the extra object, there is no docs. Also, there looks no functions to execute with them despite some options (focusPoint) exist in CanvasUtil.js. I'm not sure what the options exactly mean. I think we need tweak the codes to pass these params.

@adamellsworth
Copy link

drawImage is a very exact function which, to most users, require the ancillary options (sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight. I opted-out of react-canvas in lieu of managing our own canvas(es) as required by our components which need the source x, source y, source Width etc. on each redraw (via componentDidUpdate). I've looked through the source on react-canvas and cant' rightly see an easy way to integrate such props.

Thanks for looking into this and keep up the branches! Yours in particular helped me understand what we needed to do in order to accomplish our desired ends.

@asennikov
Copy link

Any news on that? Looks like a valuable feature, any chance it could be merged?

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

Successfully merging this pull request may close these issues.

4 participants