英文:
react-cropper - Not working properly with public images
问题
我正在进行一个React项目,使用react-cropper 这里是文档。
我获取的图片来自Laravel的公共文件,比如/public_html/public/images/etc
。
在添加参数checkCrossOrigin={false}
后,我能够加载图片并进行预览,一切正常。
但是当我尝试裁剪时出现错误。一些带有access-control-allow-origin: *
的图片可以正常工作。
以下是我在React脚本中尝试的内容:
var srcImg = 'path/of/laravel/public/image/img.png';
<Cropper
style={{ height: 400, width: "100%" }}
zoomTo={0.5}
initialAspectRatio={1}
preview=".img-preview"
src={srcImg}
checkCrossOrigin={false}
viewMode={1}
minCropBoxHeight={10}
minCropBoxWidth={10}
background={true}
responsive={true}
autoCropArea={1}
checkOrientation={false}
onInitialized={(instance) => {
setBusinessImgCropper(instance);
}}
guides={true}
/>
我认为问题出在Laravel的公共图片上。或者仍然可以修复,请告诉我。
谢谢!
英文:
I am working on a react project with react-cropper docs here
The images I am getting are coming from Laravel public files like /public_html/public/images/etc
I am able to load image and preview is also working after adding param checkCrossOrigin={false}
.
I am getting error when i trying to crop it.
some images are working fine who has access-control-allow-origin: *
Here is what i am trying with my react script
var srcImg = 'path/of/laravel/public/image/img.png';
<Cropper
style={{ height: 400, width: "100%" }}
zoomTo={0.5}
initialAspectRatio={1}
preview=".img-preview"
src={srcImg}
checkCrossOrigin={false}
viewMode={1}
minCropBoxHeight={10}
minCropBoxWidth={10}
background={true}
responsive={true}
autoCropArea={1}
checkOrientation={false}
onInitialized={(instance) => {
setBusinessImgCropper(instance);
}}
guides={true}
/>
I think the issue is on laravel public images. Or still it can be fixed let me know.
Thanks!
答案1
得分: 0
更新
以下更改适用于我:
withCredentials={true}
英文:
Update
Following changes worked for me
withCredentials={true}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论