-
Notifications
You must be signed in to change notification settings - Fork 6
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
Unclear how to use it with cropperjs #1
Comments
The It should be possible to convert the custom crop info so it can be used with other croppers as well but I haven't tested this. I've yet to make time to describe the exact way in which the crop data is calculated and used. All FilePond plugins have been open sourced today so feel free to snoop around in them and see how the data is used. The image preview and image transform plugins should expose the required info. |
Hi @rikschennink! Thank you very much for the reply. Here what I have found out about the I use
The Cropperjs data:
|
Whit this calculations explained above I get nice previews in filepond, but only if one edge of the cropbox touches one border of the image. If the cropbox is completely in the middle of the image, filepond preview zooms out from the image and the preview image is not the same as the crop area selected. Here an example of the selected crop area in the middle of the image: Here the preview created from filepond: Here a working example with left cropbox edge touching left border of the image: Here the preview created from filepond: @rikschennink can this be a bug of filepond? |
If it's in the middle it needs to zoom the image to fit correctly. The zoom factor is calculated based on the amount of space available around the rectangle. When it's against on of the edges its 1. |
Every cropper tool gives coordinates |
In my experience, |
Here an example crop with rotation: Here the generated preview: Any idea how to calculate the zoom to fit the nearest edge to the image border? Is this the calculation filepond-plugin-image-preview.esm.js#L82? |
Yes, that's it. |
@rikschennink I need help please. I'm not able to find the right calculation to zoom image to crop area. :( Any idea how I can calculate it? |
How can I zoom the image to fit correctly? I have tried many things, but no one works correctly. |
I can't help out right now, but I advise to enter some different zoom levels and see what happens to the preview. |
Here my solution with Cropperjs. It works without rotation but with flip horizontal and vertical the image: /* Constants. */
const canvasData = this.$refs.imageEditor.getCanvasData() // Cropperjs method getCanvasData()
const cropData = this.$refs.imageEditor.getData() // Cropperjs method getData()
/* Ratio of selected crop area. */
const cropAreaRatio = cropData.height / cropData.width
/* Center point of crop area in percent. */
const percentX = (cropData.x + cropData.width / 2) / canvasData.naturalWidth
const percentY = (cropData.y + cropData.height / 2) / canvasData.naturalHeight
/* Calculate available space round image center position. */
const cx = percentX > 0.5 ? 1 - percentX : percentX
const cy = percentY > 0.5 ? 1 - percentY : percentY
/* Calculate image rectangle respecting space round image from crop area. */
let width = canvasData.naturalWidth
let height = width * cropAreaRatio
if (height > canvasData.naturalHeight) {
height = canvasData.naturalHeight
width = height / cropAreaRatio
}
const rectWidth = cx * 2 * width
const rectHeight = cy * 2 * height
/* Calculate zoom. */
const zoom = Math.max(rectWidth / cropData.width, rectHeight / cropData.height)
/* Callback filepond. */
imageEditEditor.events.onconfirm({
data: {
crop: {
center: {
x: percentX,
y: percentY
},
flip: {
horizontal: cropData.scaleX < 0,
vertical: cropData.scaleY < 0
},
zoom: zoom,
rotation: (Math.PI / 180) * cropData.rotate,
aspectRatio: cropAreaRatio
}
}
}) So, rotation is not working for now. Any idea is very appreciated! |
Hi, I tried to do some things with these calculations but no results.. Filepond is beautiful but I need to integrate with my simple in-place crop editor. @rikschennink Could you help us? |
@oscarlocatelli I've written Doka.js specifically for this use case. The Image Editor plugin is mostly a proxy between FilePond and Doka, while it's possible to integrate your own image cropper/editor it's probably not as cost-effective (of course this depends on your use case) as purchasing a Doka license. If Doka does not fit your needs or you don't want to purchase a license I'm available for consulting work, please contact me on Twitter. |
@rikschennink Doka.js is great and maybe I can use it into future projects. |
The docs are currently not very detailed, in theory other plugins can be made to connect with the image-edit plugin but I haven't had a lot of time to describe this clearly. |
@hmz22 I've deleted your earlier comment, and will delete this one as well, because you already opened an issue with the exact same content, again, please don't double post. |
Anyone can’t tell me how can access imageEditeditor onconfirm event in custom editor submit button onClick function in react? |
Linking |
Will close as is inactive. |
I don't know whether this is the right solution, but works for me. I tested with few images. Only works when let x = percentX;
let y = percentY;
if (cropData.rotate == 90) {
x = 0.5 - percentY + 0.5;
y = 0.5 - percentX + 0.5;
} else if (cropData.rotate == -90) {
x = percentY;
y = percentX;
} else if (cropData.rotate == 180) {
x = 0.5 - percentX + 0.5;
y = 0.5 - percentY + 0.5;
}
/* Callback filepond. */
imageEditEditor.events.onconfirm({
data: {
crop: {
center: {
x: x,
y: y
},
flip: {
horizontal: cropData.scaleX < 0,
vertical: cropData.scaleY < 0
},
zoom: zoom,
rotation: (Math.PI / 180) * cropData.rotate,
aspectRatio: cropAreaRatio
}
}
}) |
Hi @rikschennink , Also, thanks to @phlegx for his effort in doing all the math. I just wanted to know when the What is happening is, when I look into the uploaded directory, the same image is being uploaded without any changes that the cropper has made? Any idea what am I mising? |
@TechMky Hi, yes, it will reprocess the image. Plan to add a diff here in the future, to quickly compare previous and new file metadata. |
@rikschennink I am checking the server logs, FilePond sends the file, the thing I am not able to understand is the server is saving the image but there is no change in the image whatsoever. |
Have you installed the image-transform plugin? |
@rikschennink I was just going through the code and it clicked. Indeed the image-transform plugin was missing. I came here to ask, and your answer was already here. Thanks a lot. P.S. Really like FilePond |
@rikschennink, after a few days trying, I am still struggling from the zooming issue same as @phlegx did. In my case I do not need any rotation modification, with the same zoom 'value', when the cropping box not touching the edge of the container, it zooms out. Knowing that there are some calculation to affect the zooming factors, could you suggest the correct way to calculate the zoom value if there are different cx and cy values? the way suggested by @phlegx is not fixing the issue yet. Thank you very much |
@rikschennink , OK, look forward to seeing the new updates, thank you. Btw, Your works are awesome. |
Hi @davideconte! Put the code in a Vue method (e.g. onConfirm). This method is called, when the user confirms the changes made on cropper.js. After that, I emit the data object to the filepond editor. |
Thanks, but now the problem is building the cropper :/ I already tried to create as this way: But it doesn't work :/
|
If someone's looking for it after all those years, here's a way to convert Cropper.js crop informations to Filepond's (weird) standard. Code's not optimized, mainly because it's "easier" to understand and add your own logic for flip scale if needed. Hope this helps.
|
Hi,
I'm trying to get this plugin work with my cropper using the cropperjs library. I have read the documentation of this plugin but I don't understand some parts.
crop.center.x
andcrop.center.y
? Pixel, percentage, etc.?I use
getImageData()
,getCanvasData()
andgetData()
of Cropperjs. Any idea how I can calculate all things for this filepond output object?The text was updated successfully, but these errors were encountered: