Добавить водяной знак на изображения из текста или CSV-файла - PullRequest
0 голосов
/ 30 октября 2019

У меня есть такой код:

<?php

$file = fopen("inputfile.txt", "r");
$i = 0;
while (!feof($file)) {
    $line_of_text .= fgets($file);
}
$myText = explode("\n", $line_of_text);
fclose($file);
print_r($myText);

$arrayCount = count($myText);

for ($x = 0; $x < $arrayCount; $x++) {
    $image = imagecreatefromjpeg('flower.jpg');

    // First we create our stamp image manually from GD
    $stamp = imagecreatetruecolor(200, 70);

    imagefilledrectangle($stamp, 0, 0, 199, 169, 0x0000FF);

    imagefilledrectangle($stamp, 9, 9, 190, 60, 0xFFFFFF);

    imagestring($stamp, 5, 20, 20, $myText[$x], 0x0000FF);

    imagestring($stamp, $myFont, 20, 40, '(c) 2017', 0x0000FF);
    //imagettftext ( $stamp, 5, 0, 20, 20, 20, 'arial.ttf' , "thanks!");

    // Set the margins for the stamp and get the height/width of the stamp image
    $right = 250;

    $bottom = 250;

    $sx = imagesx($stamp);

    $sy = imagesy($stamp);

    // Merge the stamp onto our photo with an opacity of 50%
    imagecopymerge($image, $stamp, imagesx($image) - $sx - $right, imagesy($image) - $sy - $bottom, 0, 0, imagesx($stamp), imagesy($stamp), 40);

    // Save the image to file and free memory
    imagepng($image, 'flower_stamp-'.$x.'.png');


    imagedestroy($image);
}

?>

И inputfile.txt выглядит так:

Category Name 1
Category Name 2
Category Name 3

Когда я запускаю этот код, он генерирует новые изображения с водяным знаком.

Проблема в том, что я использую imagestring, и я не могу определить свой собственный шрифт. Как я могу изменить семейство шрифтов до водяного знака?

...