Php 如何创建宽度和高度未知的图像?

Php 如何创建宽度和高度未知的图像?,php,php-gd,Php,Php Gd,我想从一个字符串创建一个图像,并将其缩写为使用该图像作为我正在生成的pdf的背景 这几乎不是一个问题。我希望生成的图像是全尺寸图像,我知道有两种选择: 第一:假设图像具有固定大小,并找到一种方式来表示名称必须为全尺寸(创建的图像是文本,从图像左下角开始旋转45°) 第二:假设图像具有不同的大小,这取决于名称使用的大小 我不知道我是否说得很清楚,但如果有人有任何想法,请告诉我 PS:这是我目前的代码: // Création de l'image $im = imagecreate

我想从一个字符串创建一个图像,并将其缩写为使用该图像作为我正在生成的pdf的背景

这几乎不是一个问题。我希望生成的图像是全尺寸图像,我知道有两种选择:

第一:假设图像具有固定大小,并找到一种方式来表示名称必须为全尺寸(创建的图像是文本,从图像左下角开始旋转45°)

第二:假设图像具有不同的大小,这取决于名称使用的大小

我不知道我是否说得很清楚,但如果有人有任何想法,请告诉我

PS:这是我目前的代码:

    // Création de l'image
    $im = imagecreatetruecolor();

    // Création de quelques couleurs
    $white = imagecolorallocate($im, 255, 255, 255);
    $grey = imagecolorallocate($im, 240, 240, 240);
    $black = imagecolorallocate($im, 0, 0, 0);
    imagefilledrectangle($im, 0, 0, 400, 500, $white);

    // Le texte à dessiner
    $text = $this->user->data->display_name;

    // Définition de la variable d'environnement pour GD
    putenv('GDFONTPATH=' . realpath('.'));
    // Remplacez le chemin par votre propre chemin de police
    $font = 'arial.ttf';


    // Ajout du texte
    imagettftext($im, 100, 45, 100, 500, $grey, $font, $text);

    // Utiliser imagepng() donnera un texte plus claire,
    // comparé à l'utilisation de la fonction imagejpeg()
    $this->watermark = 'watermark/'.date('Y-m-d-H-i-s').'.png';
    imagepng($im, $this->watermark);
    imagedestroy($im);

如果您知道要使用何种字体从文本创建图像,可以使用
imagettfbbox()
确定水印大小,然后使用
imagecreatetruecolor()
生成图像