-
Notifications
You must be signed in to change notification settings - Fork 127
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
Transform to image after cropping #32
Comments
Hello, @zefexdeveloper! I didn't understand your problem clearly. How do you check the size of an image at the backend and frontend? Could you try to use |
Hi @Norserium, the file size on the back end depends on what technology you are using, this project I'm using Laravel (PHP) and it's just a matter of calling If you select an image, let's say with 500kb and This was a 334kb image selected, turned 3.9mb: I will try this |
It's better to use |
@Norserium Yes, but it doesn't change the problem of having different file size on selecting and when sending. For example, the front end validation is when you select a file right? This way you can check if the file isn't bigger than 5mb, but when you crop, the file size is way bigger. The validation on the back end is when sending the image, so I can't put like 5mb max on the back end as well cause if the user selects an image on the front end that is let's say 4.5mb and crops, it will turn at least 15mb more or less so the backend won't allow it. I will try this |
What's the image type do you use for converting to |
@Norserium I was using the code above, it's pretty much the same as Do you have a project set up where you can call |
The conceptual problem consists in impossibility to preserve size of the image after drawing one at an canvas and getting one from that canvas. I can advise two ways:
I've made it now: |
@Norserium The second alternative sounds good, this way I can validate the size both on the front and on the back end without the cropping difference. I will be trying to second alternative and see if it works nice. Thank you very much. |
@zefexdeveloper, did you solve your problem? |
@Norserium Sorry the delay answering. I refactored the code in order to send the coordinates and crop on the backend but the libraries asks for integer instead of float when cropping so I had to round them. Is it possible to have an option to return the coordinates as integer? |
I will investigate this possibility. Maybe I should add the prop |
@Norserium Thank you very much, it will help me a lot, right now I have to round each one and it's pretty shitty solution. Most of the others croppers I saw they have the coordinates as integers, having both in float for precision and integer for compatibility would be great. |
Anything on this @Norserium ? Thank you |
I'm pretty busy on other projects, so I've postponed the implementing of this feature to this weekends. Sorry for the delay. |
@Norserium That is ok, wish you luck. Thank you very much. |
Please update to |
@Norserium You rock, thank you for this. It's rounded by default now right? |
Yes, I thought out and decided that's pretty optimal solution. Nonetheless, there is workaround to disable the rounding coordinates, but I couldn't come out with any situation where it might be needed. |
@Norserium Just updated here and it saved me a few lines of code rounding numbers 😆 Thank you |
Please how did you do this? Care to share some code snippets? I'm also using Laravel and I'm at my wits end because I don't know how to get the file object. Please help out. Thank you |
Hello, @simioluwatomi! I'm not @zefexdeveloper, so I can't share the code snippets, but this task should be pretty trivial. Do you want to download image on the backend or send the cropped image from the frontend to the backend? |
I've actually figured this out. Thank you! |
@simioluwatomi |
Here you go
|
I implemented the cropping with validation and everything works fine on the front end, I also need to validate the backend as the image is going to be sent from an API. If I validate on the front end as the max image size as 5MB and the same on the back end, it won't work cause as the cropper works with base64 I will have a WAY bigger image on the backend:
Do you have any idea on what I can do to solve this? I'm currently converting the base64 to an image before sending with this code:
This code will convert the base64 image from the cropper to a Blob so I can send using axios.
This way I can validate the image on the back end as well but the image sizes are way different.
The text was updated successfully, but these errors were encountered: