मैं पाठ से छवियों को उत्पन्न करने के लिए इस सरल स्क्रिप्ट का उपयोग किया गया है के साथ छवि रूप पाठ बनाने के लिए PHP जी.डी. का उपयोग करते हुए:अलग फोंट
<?php
header('Content-type: image/png');
$color = RgbfromHex($_GET['color']);
$text = urldecode($_GET['text']);
$font = 'arial.ttf';
$im = imagecreatetruecolor(400, 30);
$bg_color = imagecolorallocate($im, 255, 255, 255);
$font_color = imagecolorallocate($im, $color[0], $color[1], $color[2]);
imagefilledrectangle($im, 0, 0, 399, 29, $bg_color);
imagettftext($im, 20, 0, 10, 20, $font_color, $font, $text);
imagepng($im);
imagedestroy($im);
function RgbfromHex($hexValue) {
if(strlen(trim($hexValue))==6) {
return array(
hexdec(substr($hexValue,0,2)), // R
hexdec(substr($hexValue,2,2)), // G
hexdec(substr($hexValue,4,2)) // B
);
}
else return array(0, 0, 0);
}
?>
मैं file.php पाठ = परीक्षण स्क्रिप्ट & रंग के साथ स्क्रिप्ट कॉल = 000000
अब मुझे पता है कि मैं एक ही छवि में मिश्रित सामान्य और बोल्ड फोंट के साथ पाठ कैसे उत्पन्न कर सकता है करना चाहते हैं, जैसे file.php?text=testing <b>script</b>&color=000000
धन्यवाद कुछ मुझे यह समझने में मदद करने के लिए dqhendricks करने के लिए।
यहां एक त्वरित स्क्रिप्ट मैंने लिखा है, अभी भी सुधार की बहुत जरूरत है, लेकिन बुनियादी कार्यक्षमता के लिए यह ठीक काम कर रहा है:
<?php
header('Content-type: image/png');
$color = RgbfromHex($_GET['color']);
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$tmp = $_GET['text'];
$words = explode(" ", $tmp);
$x = array(0,0,10); // DUMMY ARRAY WITH X POSITION FOR FIRST WORD
$addSpace = 0;
foreach($words as $word)
{
if($addSpace) $word = " ".$word; // IF WORD IS NOT THE FIRST ONE, THEN ADD SPACE
if(stristr($word, "<b>"))
{
$font = 'arialbd.ttf'; // BOLD FONT
$x = imagettftext($im, 20, 0, $x[2], 20, imagecolorallocate($im, $color[0], $color[1], $color[2]), $font, str_replace(array("<b>","</b>"), "", $word));
}
else
{
$font = 'arial.ttf'; // NORMAL FONT
$x = imagettftext($im, 20, 0, $x[2], 20, imagecolorallocate($im, $color[0], $color[1], $color[2]), $font, $word);
}
$addSpace = 1;
}
imagepng($im);
imagedestroy($im);
function RgbfromHex($hexValue) {
if(strlen(trim($hexValue))==6) {
return array(
hexdec(substr($hexValue,0,2)), // R
hexdec(substr($hexValue,2,2)), // G
hexdec(substr($hexValue,4,2)) // B
);
}
else return array(0, 0, 0);
}
?>
नोट: यह केवल "बोल्ड" एकल रिक्तियों से अलग शब्दों के लिए काम करेंगे और एक शब्द के बोल्डिंग के लिए नहीं।
कॉल file.php?text=testing+<b>script</b>&color=000000
http://www.roseindia.net/tutorial/php/phpgd/About-boldtext.html प्रयास करें यह तुम क्या चाहते करने के लिए लगता है, यह है कि काला फ़ॉन्ट है ग्रे फ़ॉन्ट के शीर्ष पर, आप केवल ग्रे की स्थिति को बदल सकते हैं जिससे कि आप उन्हें कैसा लगा सकें। यूआरएल 'file.php? Text = test और bold = script और color = 000000' जैसा ही होगा। – Daniel
यह बोल्ड जैसा नहीं दिखता है, लेकिन एक छाया की तरह, और यदि मैं इसे एक-दूसरे के सामने रखता हूं तो मुझे नहीं लगता कि वे केवल एक imagettftext() के रूप में अलग दिखाई देंगे। – Meredith