admin管理员组文章数量:1296491
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
<?php
$data = urldecode($_POST['imageData']);
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
file_put_contents('image.png', $data);
?>
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
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
<?php
$data = urldecode($_POST['imageData']);
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
file_put_contents('image.png', $data);
?>
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
Share Improve this question edited May 23, 2017 at 10:27 CommunityBot 11 silver badge asked Apr 19, 2016 at 3:46 Sushanta DebSushanta Deb 5398 silver badges22 bronze badges1 Answer
Reset to default 11this works for me:
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 courtesy of Wikipedia accessed from here
本文标签: javascriptConvert Base64 to PNGJPEG file in RStack Overflow
版权声明:本文标题:javascript - Convert Base64 to PNGJPEG file in R - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741639180a2389816.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论