Open sanilcgs opened 6 years ago
Is it possible to get the exact position of the area...
Are you referring to the area of the image which is visible when cropped?
Or something else?
I've been running into this as well. I'm trying to use the pan/zoom functionality to crop an image, but I'm not quite sure how to calculate it without a better understanding of what scale
and zoomCurrentDistance
mean relative to the image vs window dimensions. Can you explain that these data points imply so that I can better understand how to crop accurately? Thank you.
I would like to have this as well. Would like to know how to compute the area being zoomed with relation to the original image. Like left, top, width, height.
Are you referring to the area of the image which is visible when cropped? -> Would be great if we are able to compute this.
Thanks.
@genogeno can you suggest an API that you reckon would be nice?
What props, args, callbacks would make sense?
On Tue, 29 Jan 2019 at 5:40 pm, genogeno notifications@github.com wrote:
I would like to have this as well. Would like to know how to compute the area being zoomed with relation to the original image. Like left, top, width, height.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ascoders/react-native-image-zoom/issues/69#issuecomment-458425045, or mute the thread https://github.com/notifications/unsubscribe-auth/ACAqW08Rpvf5wfkgROgEFII9CdEMR4GXks5vH-ysgaJpZM4XYKl8 .
I think it would be nice to be added as a new property to IOnMove object.
As added key-value pair for position object. onMove | ( position: IOnMove )=>void
If it also possible to add a new callback that will be called when the move has ended. onMoveEnd | ( position: IOnMove )=>void
@ascoders what do you think?
It's nice to have, welcome pr! @brycehanscomb @genogeno 👍
While a separate onMoveEnd
is a nice bit of sugar, you can already achieve that by filtering the position type
in onMove
to onPanResponderRelease
.
@dbecker215 @genogeno I realise your comments are nearly a month old, but hopefully this may be useful for you. I’ve just had to work through calculating the dimensions and position of a cropped image and here’s my solution:
Note: this assuming you’re using an image view that has its
resizeMode
set tocover
cover
resize mode:const widthDownscalingFactor = originalImageWidth / cropWidth;
const heightDownscalingFactor = originalImageHeight / cropHeight;
// For portrait images
const scaledImageWidth = cropWidth * position.zoomScale;
const scaledImageHeight = cropHeight * (originalImageHeight / originalImageWidth) * position.zoomScale;
// For landscape images
const scaledImageWidth = cropWidth * (originalImageWidth / originalImageHeight) * position.zoomScale;
const scaledImageHeight = cropHeight * position.zoomScale;
// For square images
const scaledImageWidth = cropWidth * position.zoomScale;
const scaledImageHeight = cropHeight * position.zoomScale;
const scaledCropWidth = cropWidth / position.zoomScale;
const scaledCropHeight = cropWidth / position.zoomScale;
const originX = (scaledImageWidth - scaledCropWidth) / 2
const originY = (scaledImageHeight - scaledCropHeight) / 2
const x = originX - position.positionX;
const y = originY - position.positionY;
const cropRect = {
originX: x * widthDownscalingFactor,
originY: y * heightDownscalingFactor,
width: cropWidth * widthDownscalingFactor,
height: cropHeight * heightDownscalingFactor,
}
Hello! I created a small component for cropping based on this component - react-native-simple-image-cropper. @dbecker215 @genogeno you can see how the values you need are calculated here.
@neilco I am trying to get your code working but I am always getting different Y... Is it possible that you post a snack? Thanks!
I have tried for getting the position of zoomed portion of an image using the onMove props. I got a position object after every pan. I couldn't understand how will the position object change during each pan move. Is it possible to get the exact position of the area using this object or any other suggestion to get the position?