Comments (6)
I am also seeing this issue.
from react-image-crop.
I used to have a zoom
prop, perhaps something like that can fix it 🤔
/** A non-visual prop to keep pointer coords accurate when a parent element is scaled.
Not to be confused with the `scale` prop which scales the image itself. Defaults to 1. */
zoom?: number
https://github.com/sekoyo/react-image-crop/blob/9.1.1/src/ReactCrop.tsx#L358
https://github.com/sekoyo/react-image-crop/blob/9.1.1/src/ReactCrop.tsx#L436
Are you able to make an example of the issue on React Flow (haven't used or heard of it before)?
from react-image-crop.
React Flow is a library used for node based workflows. The way the zoom works under the hood is utilizing transform: scale
with CSS, so you can just wrap a ReactCrop element in a scaled div to see the same effect. Here is the result of doing that with the CodeSandbox example:
https://codesandbox.io/p/sandbox/react-image-crop-demo-with-react-hooks-forked-with-zoomed-out-container-gqjwpg
It would be possible to make a CodeSandbox with React Flow in particular, but that would require more boilerplate since you need to define all your node types. In my current project, the behavior is slightly different than the example above as the cropped output is accurate to the crop area visually. It just won't let you set the crop area to larger than the zoom amount. In other words, the screenshot I attached above is the maximum selectable area.
I believe bringing that zoom
prop back would do the trick in both cases though.
from react-image-crop.
Sorry I misread - looks like it's only an issue with the crop preview.
So you can modify it like:
async function canvasPreview(
image: HTMLImageElement,
canvas: HTMLCanvasElement,
crop: PixelCrop,
scale = 1,
rotate = 0,
appScalePc = 100,
) {
const ctx = canvas.getContext('2d')
if (!ctx) {
throw new Error('No 2d context')
}
const scaleX = (image.naturalWidth / image.width) * (100 / appScalePc)
const scaleY = (image.naturalHeight / image.height) * (100 / appScalePc)
// ....
}
And if your transform: 'scale(50%)'
is 50%, then pass 50
to appScalePc
from react-image-crop.
Would it still be possible to expose that zoom prop?
from react-image-crop.
I fixed this with the following subclass - would it be possible to expose a scale or zoom parameter as it seems like it does this?
interface ScaleCompatibleReactCropProps {
scale?: number
}
class ScaleCompatibleReactCrop extends ReactCrop {
props: ReactCropProps & ScaleCompatibleReactCropProps
getBox() {
const box = super.getBox()
const { scale } = this.props
if (scale !== undefined) {
box.width /= scale
box.height /= scale
}
return box
}
}
from react-image-crop.
Related Issues (20)
- Canvas returns null after cropping image iOS HOT 2
- Mask is does'nt showing the first time HOT 8
- Memory leak risk due to event listeners not removed on componentWillUnmount HOT 1
- mask does not fully cover the image when the image to a smaller aspect ratio HOT 2
- Multiple crop selection on an image at the same time HOT 1
- Can the cropper be used for outpainting?
- React Crop as Dialog Box
- The previous image layout still be kept after switch image HOT 1
- Feature request: Add the option to rotate the crop selection
- Proportional Stretching of Crop Box
- iPhone 15's 24 MP (res 4284 X 5712) image resolution is making the image black after cropping. HOT 1
- Library not supporting image cropping in iOS WebView HOT 6
- Add whitespace around image being cropped?
- Deprecation Warnings with SASS 1.77.7 HOT 2
- Maximum Scale Out to produce only complete image without any transparent parts added to result HOT 4
- reload saved cropped image, onComplete returning incorrect crop, but percentCrop is correct.
- Height styling not working with percentages
- While trying to rotate the image, the image itself is not fitting inside the container, full image is not visible after rotating to 90 or 270 degree HOT 5
- expand image to fit container HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-image-crop.