Всем привет! Пишу на PHP скрипт, который будет наносить текст на изображение и столкнулся с проблемой, что в моей библиотеке php-image нет форматирования по абзацу.
Цитата:
Сообщение от Спойлер
На Стеке в разделе Питона прочитал что нужно «разбить его пробелами и вставить пробелы, чтобы заполнить оставшееся пространство»
Цитата:
Сообщение от Спойлер
Python:
Код:
from
PIL
import
Image
,
ImageDraw
,
ImageFont
font
=
ImageFont
.
truetype
(
"arial.ttf"
,
20
)
text
=
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"
\
"Pellentesque accumsan nec felis ut vulputate."
image_width
=
600
im
=
Image
.
new
(
"RGB"
,
(
image_width
,
80
)
,
"white"
)
d
=
ImageDraw
.
Draw
(
im
)
y
=
10
for
line
in
text
.
split
(
"\n"
)
:
words
=
line
.
split
(
" "
)
words_length
=
sum
(
d
.
textlength
(
w
,
font
=
font
)
for
w
in
words
)
space_length
=
(
image_width
-
words_length
)
/
(
len
(
words
)
-
1
)
x
=
0
for
word
in
words
:
d
.
text
(
(
x
,
y
)
,
word
,
font
=
font
,
fill
=
"black"
)
x
+=
d
.
textlength
(
word
,
font
=
font
)
+
space_length
y
+=
30
Как на php реализовать этот же код? Или есть какие-то другие решения?