I’m trying to create a vertical button in PHP, but I have problem with the positioning, when I created a 200px height and 40px width PNG i want to put the text to the center of that image. The text long will be changing dynamically
this is a part of my code
$image = imagecreate($this->width , $this->height);
$background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn, $this->bg_blu);
$foreground = ImageColorAllocate($image, $this->red, $this->grn, $this->blu);
if ($this->transparent) ImageColorTransparent($image, $background);
ImageInterlace($image, false);
// render the image
ImageTTFText($image, $this->size, $this->rot, $offset_x, $offset_y, $foreground, $this->font, $this->msg);
how can I calculate the $offset_x and $offset_y?
As you can see in the documentation of
imagettftextfunction, itSo you can first draw the text on another image, just to see what the dimensions will be, then calculate the needed height of your button.