Y
Y
YariKartoshe4ka2019-09-16 15:44:45
PHP
YariKartoshe4ka, 2019-09-16 15:44:45

How to put text on a picture with an eyeliner?

I overlay text on the image like this:

<?php

  $img = "./test.jpg"; // Ссылка на файл
  $font = "./Impact.ttf"; // Ссылка на шрифт
  $font_size = 24; // Размер шрифта
  $degree = 0; // Угол поворота текста в градусах
  $text = "Hello, World!"; // Ваш текст
  $y = 100; // Смещение сверху (координата y)
  $x = 200; // Смещение слева (координата x)
  $pic = imagecreatefromjpeg($img); // Функция создания изображения
  $color = imagecolorallocate($pic, 0, 0, 0); // Функция выделения цвета для текста
  
  imagettftext($pic, $font_size, $degree, $x, $y, $color, $font, $text); // Функция нанесения текста
  imagepng($pic, "./".time().".jpg"); // Сохранение рисунка
  imagedestroy($pic); // Освобождение памяти и закрытие рисунка
  
?>

There were two questions:
1. How and whether it is possible to overlay text with a frame at all? If the color is 250 250 250, then it will just be white text, I would like to have a black strip around each letter (frame, stroke)
2. Is it possible to center the text horizontally (so that it is exactly in the middle of the image horizontally)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-09-18
@YariKartoshe4ka

1. you need to draw text with an offset
2. to align the text, you need to calculate the frame,
for example, imagick has location constants, in gd I had to calculate
such crutches I had to sculpt on gd
https://github.com/Compolomus/Compomage/blob/maste ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question