Anonymous
Как добавить непрозрачность на текст с тенью на картинке?
Сообщение
Anonymous » 17 сен 2025, 02:40
Я использую эту функцию, чтобы добавить текст с тенью на картинке: < /p>
Код: Выделить всё
function addWatermark($image, $text){
// Schriftdatei (TrueType Font)
$fontPath = __DIR__ . "/NotoSansSymbols-Regular.ttf";
// Text und Schriftgröße
$fontSize = 18; // in Punkten
// Farben definieren
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
// Bildgröße
$imageWidth = imagesx($image);
$imageHeight = imagesy($image);
if($imageWidth < 550){
$fontSize = 16;
}
// Textgröße berechnen
$bbox = imagettfbbox($fontSize, 0, $fontPath, $text);
$textWidth = abs($bbox[2] - $bbox[0]);
$textHeight = abs($bbox[7] - $bbox[1]);
// Padding (20% des Bildes)
$paddingY = 10;
$paddingX = 10;
// Obere rechte Position berechnen
$x = $imageWidth - $textWidth - $paddingX;
$y = $paddingY + $textHeight; // Y-Koordinate ist baseline
// Schwarzen Rand dünner zeichnen (nur oben, unten, links, rechts)
imagettftext($image, $fontSize, 0, $x - 1, $y, $black, $fontPath, $text); // links
imagettftext($image, $fontSize, 0, $x + 1, $y, $black, $fontPath, $text); // rechts
imagettftext($image, $fontSize, 0, $x, $y - 1, $black, $fontPath, $text); // oben
imagettftext($image, $fontSize, 0, $x, $y + 1, $black, $fontPath, $text); // unten
// Weißen Text darüber
imagettftext($image, $fontSize, 0, $x, $y, $white, $fontPath, $text);
return $image;
}
Я хочу добавить непрозрачность 70% к окончательному тексту, как я могу это сделать?
Подробнее здесь:
https://stackoverflow.com/questions/797 ... -a-picture
1758066037
Anonymous
Я использую эту функцию, чтобы добавить текст с тенью на картинке: < /p> [code]function addWatermark($image, $text){ // Schriftdatei (TrueType Font) $fontPath = __DIR__ . "/NotoSansSymbols-Regular.ttf"; // Text und Schriftgröße $fontSize = 18; // in Punkten // Farben definieren $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); // Bildgröße $imageWidth = imagesx($image); $imageHeight = imagesy($image); if($imageWidth < 550){ $fontSize = 16; } // Textgröße berechnen $bbox = imagettfbbox($fontSize, 0, $fontPath, $text); $textWidth = abs($bbox[2] - $bbox[0]); $textHeight = abs($bbox[7] - $bbox[1]); // Padding (20% des Bildes) $paddingY = 10; $paddingX = 10; // Obere rechte Position berechnen $x = $imageWidth - $textWidth - $paddingX; $y = $paddingY + $textHeight; // Y-Koordinate ist baseline // Schwarzen Rand dünner zeichnen (nur oben, unten, links, rechts) imagettftext($image, $fontSize, 0, $x - 1, $y, $black, $fontPath, $text); // links imagettftext($image, $fontSize, 0, $x + 1, $y, $black, $fontPath, $text); // rechts imagettftext($image, $fontSize, 0, $x, $y - 1, $black, $fontPath, $text); // oben imagettftext($image, $fontSize, 0, $x, $y + 1, $black, $fontPath, $text); // unten // Weißen Text darüber imagettftext($image, $fontSize, 0, $x, $y, $white, $fontPath, $text); return $image; } [/code] Я хочу добавить непрозрачность 70% к окончательному тексту, как я могу это сделать? Подробнее здесь: [url]https://stackoverflow.com/questions/79766760/how-to-add-opacity-to-text-with-shadow-on-a-picture[/url]