1

すべてのパラメーターが動的である特定のテンプレートでテキスト画像を作成していますが、正常に機能しています! そして、私のphpスクリプトのような画像を作成するのは、

<?php
// To fetch template info from database
$template_query = mysql_query("SELECT * FROM templates WHERE templateID = '".$fetch['templateID']."'");
$temp_data = mysql_fetch_assoc($template_query);
//create and save images
$temp = '../'. $temp_data['blank_templates'];
//check image type
$image_extension = strtolower(substr(strrchr($temp_data['blank_templates'], "."), 1));

    $im = imagecreatefromjpeg($temp);

$black = hexdec($temp_data['font_color']);
// Replacing path by your own font path
$font = '..'.$temp_data['font_file_upload'];

// Break it up into pieces 125 characters long
$no_of_characters_line = $temp_data['no_of_characters_line'];
$lines = explode('|', wordwrap($message, $no_of_characters_line, '|'));
// Starting Y position and X position
$y = $temp_data['position_from_top'];
$x = $temp_data['position_from_left'];
$font_size = $temp_data['font_size'];
$rotation_angle = $temp_data['rotation'];
$line_height = $temp_data['line_height'];

foreach ($lines as $line)
{
    imagettftext($im, $font_size,$rotation_angle, $x, $y, $black, $font, $line);
    // Increment Y so the next line is below the previous line
    $y += $line_height;
}
$id = uniqid();
$save = '../messagesimage/'.$id. '.'.$image_extension;
$path_save = substr($save, 3);
// Using imagepng() results in clearer text compared with imagejpeg()
        imagejpeg($im,$save);

imagedestroy($im);

のようなイメージを作成しています..!ここに画像の説明を入力

フォントの不透明度とシャドウイングを動的に変更する機能を追加したいのですが、可能ですか? はいの場合、これを行うのを手伝ってください..

前もって感謝します

4

2 に答える 2

3

おお、大変お待たせいたしました。

テキストにある程度の透明度を与えるには、アルファ チャネルを使用してテキストの色を定義する必要があります。

$black = imageallocatecoloralpha(0,0,0,16);

テキストに影を付けるには

$shadow = imageallocatecoloralpha(0,0,0,64); // more transparent
imagettftext($im, $font_size,$rotation_angle, $x+1, $y+1, $shadow, $font, $line);
imagettftext($im, $font_size,$rotation_angle, $x, $y, $black, $font, $line);
于 2014-01-17T06:04:16.943 に答える
3

後になっても、現在の答えは間違っているようです。

透明度のある色を定義するには、次の関数を使用しますimagecolorallocatealpha()

$black = imagecolorallocatealpha($image, 0, 0, 0, 50);

マイケルが指摘したように、シャドウは非常に単純です (正しい関数名を使用し、必ず画像オブジェクトを追加してください)。ただし、より影のように見える影が必要な場合は、少しぼかします。

$shadow = imagecolorallocatealpha($im, 0, 0, 0, 50);
//Draw shadow text
imagettftext($im, $font_size, 0, $x, $y, $shadow, $fontn, $text);
//Blur
imagefilter($im, IMG_FILTER_GAUSSIAN_BLUR);
//Draw text
imagettftext($im, $font_size, 0, $x, $y, $white, $fontn, $text);

上記のシャドウ メソッドを画像に適用すると、次のようにレンダリングされます。

サンプル画像

于 2016-06-18T17:22:40.523 に答える