@@ -344,25 +344,29 @@ public String getCroppedImageDataUri() {
344
344
}
345
345
346
346
/**
347
- * Returns the cropped image data URI as a Base64 encoded byte array. If the image data URI does
348
- * not contain "image/*;base64,", it will be decoded to prevent a null pointer exception.
347
+ * Decodes the cropped image data URI and returns it as a byte array. If the image data URI is not
348
+ * in the format "data:image/*;base64,", it will be decoded assuming it is a Base64 encoded
349
+ * string.
349
350
*
350
- * <p>
351
- * This method incorporates work licensed under MIT.
352
- * Copyright 2021-2023 David "F0rce" Dodlek https://github.com/F0rce/cropper
351
+ * <p>
352
+ * This method incorporates work licensed under MIT. Copyright 2021-2023 David "F0rce" Dodlek
353
+ * https://github.com/F0rce/cropper
353
354
* </p>
354
355
*
355
- * @return byte[] the Base64 encoded byte array of the cropped image
356
+ * @return byte[] the decoded byte array of the cropped image
356
357
*/
357
358
public byte [] getCroppedImageBase64 () {
358
359
String croppedDataUri = this .getCroppedImageDataUri ();
359
360
if (StringUtils .isBlank (croppedDataUri )) {
360
361
return null ;
361
362
}
362
- String split = croppedDataUri .split ("," )[1 ];
363
- return (split .length () == 0 )
364
- ? Base64 .getDecoder ().decode (croppedDataUri .getBytes (StandardCharsets .UTF_8 ))
365
- : Base64 .getDecoder ().decode (split .getBytes (StandardCharsets .UTF_8 ));
363
+
364
+ String base64Data = croppedDataUri ;
365
+ if (croppedDataUri .contains ("base64," )) {
366
+ base64Data = croppedDataUri .split ("," )[1 ];
367
+ }
368
+
369
+ return Base64 .getDecoder ().decode (base64Data .getBytes (StandardCharsets .UTF_8 ));
366
370
}
367
371
368
372
}
0 commit comments