Convert Base64 to PNG/JPEG file in R(在 R 中将 Base64 转换为 PNG/JPEG 文件)
问题描述
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
this 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
这篇关于在 R 中将 Base64 转换为 PNG/JPEG 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 R 中将 Base64 转换为 PNG/JPEG 文件


基础教程推荐
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01