javascript - Convert Base64 to PNG/JPEG file in R -
i have seen process convert png file base64 work in post below convert r image base 64
i exact opposite of did. have base64 of image stored in variable "capimg" , want convert png or jpeg file. can me reverse engineer process.
is doable?
i have seen done using php below need r script 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 able decode base64 vector using base64enc package below y <- base64decode(capimg)
but not know how proceed further
this works 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 here
Comments
Post a Comment