2014-11-13 4 views
5

मैं बहु रंगीन पाठ के साथ PHP जीडी लाइब्रेरी का उपयोग करके टेक्स्ट को सीमा कैसे दे सकता हूं, जहां टेक्स्ट रंग सीमा रंग से अलग है।PHP जीडी लाइब्रेरी में पाठ को सीमा कैसे दें

आप उल्लेख कर सकते हैं के रूप में: सीमा पाठ को जोड़ने के लिए

enter image description here

+1

कृपया हमें दिखाने के तुम क्या कोशिश की है। – zessx

उत्तर

1
// http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/ 
function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) { 
for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++) 
    for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++) 
     $bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text); 
    return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text); 
} 

$font_color = imagecolorallocate($im, 255, 255, 255); 
$stroke_color = imagecolorallocate($im, 0, 0, 0); 
imagettfstroketext($im, 60, 10, 300, 130, $font_color, $stroke_color, "wqy- microhei.ttc", "简体繁體", 2); 
9

उपयोग निम्नलिखित समारोह

आप उदाहरण के उत्पादन यहाँ http://wmh.github.io/hunbook/examples/gd-imagettftext.html

function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) { 
    for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++) 
     for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++) 
      $bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text); 
    return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text); 
} 
+1

यह अच्छा काम करता है धन्यवाद –

+0

मैं जीडी लाइब्रेरी पर काम कर रहा हूं और गुणवत्ता के बिंदु पर थोड़ा उलझन में आपकी मदद की ज़रूरत है –

4

आप कर सकते हैं जाँच कर सकते हैं stil/gd-text कक्षा पुस्तकालय का उपयोग करें। कोड उदाहरण:

<?php 
require __DIR__.'/../vendor/autoload.php'; 

use GDText\Box; 
use GDText\Color; 

$im = imagecreatetruecolor(500, 500); 
$backgroundColor = imagecolorallocate($im, 0, 18, 64); 
imagefill($im, 0, 0, $backgroundColor); 

$box = new Box($im); 
$box->setFontFace(__DIR__.'/Elevant bold.ttf'); // http://www.dafont.com/elevant-by-pelash.font 
$box->setFontSize(150); 
$box->setFontColor(new Color(255, 255, 255)); 
$box->setBox(20, 20, 460, 460); 
$box->setTextAlign('center', 'center'); 

$box->setStrokeColor(new Color(255, 75, 140)); // Set stroke color 
$box->setStrokeSize(3); // Stroke size in pixels 

$box->draw("Elevant"); // Text to draw 

header("Content-type: image/png;"); 
imagepng($im, null, 9, PNG_ALL_FILTERS); 

प्रदर्शन:

demo

संबंधित मुद्दे