magick
magick copied to clipboard
Inconsistency in text positioning with image_annotate()
Hi,
I'm trying to add annotation to my images and combine them in single composite image. I'm facing a problem with text positioning. When I use gravity = "north"
the results is consistent with expectations (i.e. text centered horizontally and located at the top of the frame). However, when I'm trying to add annotation to the left using degree = -90, gravity = "west"
the half of the text is cropped and it is not centered vertically. Do I misunderstand something?
This one is good:
This one is no good:
Here is reprex:
library(magick)
## This works perfectly
image_read("./temp/Day_2_XY06_CH4.png") %>%
image_border(color = "#FFFFFF", geometry = "0x25") %>%
image_annotate(text = "EdU",
font = "serif",
weight = 700,
size = 20,
color = "magenta",
gravity = "north") %>%
image_trim()
## Here I have a problem
image_read("./temp/Day_2_XY06_CH4.png") %>%
image_border(color = "#FFFFFF", geometry = "25x0") %>%
image_annotate(text = "EdU",
font = "serif",
weight = 700,
size = 20,
color = "magenta",
degrees = -90,
gravity = "west") %>%
image_trim()
I realize you may be pointing out inconsistent behavior, but a work-around may be to adjust the location:
wizard %>%
image_border(color = "#504050", geometry = "25x25") %>%
image_annotate(text = "EdU",
font = "serif",
weight = 700,
size = 20,
color = "white",
boxcolor= "green",
degrees = -90,
location = "+12+0",
gravity = "west"
)
I guess specifying the location offset would be difficult programatically (i.e., when the font changes or the font size changes, it wouldn't be clear what good location values would be).