... Ideally, with a PNG image file, if not JPEG. I can load a flie with
library(png)
img = readPNG("chart.png")
but am stuck there. The goal is to type "Hello world" on the image and save it.
Thank you.
I think this should work just fine
library(png)
#read file
img<-readPNG("33.png")
#get size
h<-dim(img)[1]
w<-dim(img)[2]
#open new file for output
png("out.png", width=w, height=h)
par(mar=c(0,0,0,0), xpd=NA, mgp=c(0,0,0), oma=c(0,0,0,0), ann=F)
plot.new()
plot.window(0:1, 0:1)
#fill plot with image
usr<-par("usr")
rasterImage(img, usr[1], usr[3], usr[2], usr[4])
#add text
text(.5,.5, "hello", cex=5, col=rgb(.2,.2,.2,.7))
#close image
dev.off()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With