DJD
DJD

Reputation: 83

Text Alignment in R Magick package

I am trying to align text to its placement coordinate centrally using the magick package in R and image_annotate...

So in this example

#Load Graphic
pb<-image_read("https://art.pixilart.com/8c9cffeb529b204.png")
#Place text at central coordinate
image_draw(pb) %>% 
  image_annotate("Centre",location=geometry_point(610.5,610.5), color = "red", size = 50)

the top right of the word "Centre" is(roughly) aligned with the provided coordinate.

Is it possible to set a command (equivalent to hjust, vjust etc) that would align the text centrally....

it seems that although ImageMagick might have some of this functionality, it doesn't look like all the commands and parameters have ported over to the R package (though I may be missing something)

Upvotes: 1

Views: 137

Answers (1)

Peter
Peter

Reputation: 12739

Does this work?

library(magick)

#Load Graphic
pb<-image_read("https://art.pixilart.com/8c9cffeb529b204.png")
#Place text at central coordinate
image_draw(pb) |>  
  image_annotate("Centre",
                 color = "red", 
                 size = 50,
                 gravity = "center")

enter image description here

Upvotes: 0

Related Questions