在R中将Base64转换为PNG/JPEG文件 [英] Convert Base64 to PNG/JPEG file in R
问题描述
我在下面的帖子中看到了将png文件转换为base64的过程 将R图像转换为Base 64 >
我想做的和你做的完全相反.我将图像的base64存储在变量"capimg"中,现在我想将其转换为png或jpeg文件.您能帮我对流程进行逆向工程吗?
这可行吗?
我已经看到使用php来完成此操作,如下所示,但我需要一个R脚本来完成该操作
<?php
$data = urldecode($_POST['imageData']);
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
file_put_contents('image.png', $data);
?>
实际上,我还可以使用base64enc包将base64解码为向量,如下所示 y<-base64decode(capimg)
但是我不知道该怎么做
这对我有用:
library(base64enc)
enc <- base64encode("images.jpg")
conn <- file("w.bin","wb")
writeBin(enc, conn)
close(conn)
inconn <- file("w.bin","rb")
outconn <- file("img2.jpg","wb")
base64decode(what=inconn, output=outconn)
close(inconn)
close(outconn)
images.jpg由Wikipedia提供,该维基百科可从 I have seen the process to convert a png file to base64 work in the post below
Convert R image to Base 64 I would like to do the exact opposite of what you did. I have a base64 of a image stored in a variable "capimg" and now I want to convert it into a png or jpeg file. Can you help me reverse engineer the process. Is this doable? I have seen this done using php like below but I need a R script to do the same In fact I am also able to decode the base64 into a vector using the base64enc package like below
y <- base64decode(capimg) But I do not know how to proceed any further this works for me: images.jpg courtesy of Wikipedia accessed from here 这篇关于在R中将Base64转换为PNG/JPEG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!<?php
$data = urldecode($_POST['imageData']);
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
file_put_contents('image.png', $data);
?>
library(base64enc)
enc <- base64encode("images.jpg")
conn <- file("w.bin","wb")
writeBin(enc, conn)
close(conn)
inconn <- file("w.bin","rb")
outconn <- file("img2.jpg","wb")
base64decode(what=inconn, output=outconn)
close(inconn)
close(outconn)