Decoding Error occurs when supplying a cropped image from client using CropperJS #2250
Answered
by
ChanManChan
ChanManChan
asked this question in
Q&A
-
Trying to create a thumbnail for the cropped image using CropperJs and am getting this error: [1] called Client code: const canvas = cropper.current.getCroppedCanvas()
if (!canvas) return
canvas.toBlob((blob) => {
URL.revokeObjectURL(fileUrl.current)
fileUrl.current = URL.createObjectURL(blob)
setFile(blob)
}) Server Code: let original_img = image::open(&disk_path).unwrap();
let thumbnail_img = original_img.thumbnail(200, 200);
let mut tiny_image = fs::File::create(&tiny_disk_path).unwrap();
let compress_result = thumbnail_img.write_to(&mut tiny_image, image::ImageFormat::Png); Please help since non cropped image gets thumbnailed correctly. The issue only exists for cropped images. What could be the problem? The image thumbnail creation worked fine with sharp when I used to have a NodeJS backend. |
Beta Was this translation helpful? Give feedback.
Answered by
ChanManChan
Jun 2, 2024
Replies: 1 comment
-
it started working when I added this extra code let original_img = match image::open(&disk_path) {
Ok(dyn_image) => dyn_image,
Err(_) => Reader::new(Cursor::new(file_data))
.with_guessed_format()
.unwrap()
.decode()
.unwrap(),
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ChanManChan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it started working when I added this extra code