将base64转换为打字稿/Angular中的功能性JPEG
我正在浏览器中的静态图像上运行cropperjs(从jpeg格式中从nodejs服务器检索),它返回了基本64中不同图像中的预览。我试图以原始的JPEG格式获取数据并将修改后的图像保存回服务器。 我已经尝试了一些不同的事情,但这是最新的:
saveCroppedImage(){
var split = this.imageDestination.split(','); // parsing out data:image/png;base64,
var croppedImage = split[1]; // assigning the base64 to a variable
var blob = new Blob([croppedImage],{type: 'image/jpeg'}); //changing the base64->Blob
var file = new File([blob],'cropped.jpeg'); //theoretically changing the blob->jpeg
this.newCroppedImage = file;
}
然后,我将文件上传到服务器,并损坏。
I am running cropperjs on a static image in the browser(retrieved from a nodejs server in jpeg format), it returns a preview in a different image that is in base64. Im trying to take that data and save the modified image back to the server in the original jpeg format.
I've tried a few different things, but this is the latest:
saveCroppedImage(){
var split = this.imageDestination.split(','); // parsing out data:image/png;base64,
var croppedImage = split[1]; // assigning the base64 to a variable
var blob = new Blob([croppedImage],{type: 'image/jpeg'}); //changing the base64->Blob
var file = new File([blob],'cropped.jpeg'); //theoretically changing the blob->jpeg
this.newCroppedImage = file;
}
I then upload the file to the server and it is corrupted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,所以我在Interweb的一些帮助下弄清楚了:
这是我必须在文件创建中包含的信息,并且确实必须保持PNG才能工作。
savecroppedimage(){
}
Ok, so I figured it out with some help of the interweb:
This is the info I had to include with the file creation, and it did have to stay a png to work.
saveCroppedImage() {
}