gl-react icon indicating copy to clipboard operation
gl-react copied to clipboard

Incorrect rotation of the image ( iOS 12 )

Open Orxcle-xx opened this issue 7 years ago • 4 comments

Incorrect rotation of the image ( iOS 12 )

library versions

"gl-react": "^3.14.0",
"gl-react-image": "^3.1.1",
"gl-react-native": "^3.14.0",
"react-native-webgl": "^0.8.0"

Expected behavior

Image is properly shown and not rotated, works similarly as native component.

Actual behavior

Image is rotated.

Steps to reproduce the behavior

Hi,

I use a camera ( see the link: https://github.com/react-native-community/react-native-camera ). After it I managed to insert a link to the local file ( ie file:// ), using two options: <Surface style={{width: 300, height: 400}}> <Saturate {...filterProps}> {{ image : { uri: photoUri }}} </Saturate> </Surface> or <Surface style={{width: 300, height: 400}}> <Saturate {...filterProps}> <GLImage source={{ image : { uri: photoUri }}} height={300} width={400}/> </Saturate> </Surface>

In both cases an image is rotated. If I use standard component, Image is properly shown. NB! I also tried different options ( see property forceUpOrientation ) as described here: https://github.com/react-native-community/react-native-camera/blob/master/docs/RNCamera.md The rotation of the image changed...but it still rotated..

Any clues? Thank you.

Orxcle-xx avatar Dec 04 '18 09:12 Orxcle-xx

@Orxcle-xx Can I assume both cases use the same orientation? Portrait or landscape? It would also be helpful to see the code for your component, for now I will assume it is the example from the cookbook.

With the above assumptions my guess is that you need to rotate the image according to it's orientation. This can be done inside the shader.

Here is some example code from one of my projects

 vec3 ouv;
  if (resolution.y > resolution.x) {
    float flipY = 1.0 - uv.y;
    ouv = vec3(flipY, uv.x, 0);
  } else {
    ouv = vec3(uv.x, uv.y, 0);
  }
  vec4 c = texture2D(backgroundImage, vec2(ouv.x, ouv.y));

Note that the above first switches the x and y values for the uv according to orientation and because portraits always come out upside-down I simply flip that across the Y axis.

brysonandrew avatar Jan 23 '19 11:01 brysonandrew

@Orxcle-xx I updated by answer on anther thread you made but for reference, please try and shrink your image, the rotation issue should go away.

brysonandrew avatar Mar 14 '19 14:03 brysonandrew

I'm also having the exact same issue, has anyone found a solution yet?

davidcian avatar Sep 30 '19 19:09 davidcian

What you can do is flip the camera stream, the data of the image stream are yflipped but this is possible to do this:

https://github.com/gre/gl-react/blob/master/examples/cookbook-rn-shared/examples/camera/GLCamera.js

and

https://github.com/gre/gl-react/blob/master/examples/cookbook-rn-shared/examples/camera/index.js

gre avatar Jan 01 '20 14:01 gre