Convert Base64 to PNG/JPEG file in R

后端 未结 1 1914
甜味超标
甜味超标 2020-12-17 02:53

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 ha

1条回答
  •  南方客
    南方客 (楼主)
    2020-12-17 03:32

    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

    0 讨论(0)
提交回复
热议问题