2013-02-21 49 views
6

यह लंबे समय तक है कि मैं अभी भी इस समस्या का उत्तर ढूंढ रहा हूं .. मेरे द्वारा प्राप्त सभी समाधान फ़ॉन्ट नाम को पकड़ने के आसपास हैं लेकिन मुझे पूरा यकीन है कि यह मेरा नहीं है मुसीबत।PHP - imagettftext काम नहीं कर रहा है और जीडी स्थापित

यह जी.डी. तरह लग रहा है स्थापित किया गया है

array(11) { 
    ["GD Version"]=> 
    string(27) "bundled (**2.0.34 compatible**)" 
    ["FreeType Support"]=> 
    bool(false) 
    ["T1Lib Support"]=> 
    bool(false) 
    ["GIF Read Support"]=> 
    bool(true) 
    ["GIF Create Support"]=> 
    bool(true) 
    ["JPEG Support"]=> 
    bool(true) 
    ["PNG Support"]=> 
    bool(true) 
    ["WBMP Support"]=> 
    bool(true) 
    ["XPM Support"]=> 
    bool(true) 
    ["XBM Support"]=> 
    bool(true) 
    ["JIS-mapped Japanese Font Support"]=> 
    bool(false) 
} 

से ऊपर तुम मेरे जी.डी. समर्थन देख सकते हैं। मेरा PHP संस्करण 5.3 है और मैं लिनक्स पर चल रहा हूं।

मैंने विभिन्न वेबसाइटों से कुछ अलग कोड उदाहरणों की कोशिश की है और कोई भी काम नहीं करता है। ImageString मेरे लिए काम करता है, लेकिन मैं imagettftext काम करने के लिए प्राप्त करने की आवश्यकता ..

यह पिछले कोड रहा है अब की कोशिश की है है

<?php 
ini_set('display_errors', 1); 
error_reporting(E_ALL); 

// Set the content-type 
header('Content-Type: image/png'); 

// Create the image 
$im = imagecreatetruecolor(400, 100) or die("Can't create image!"); 

// Create some colors 
$white = imagecolorallocate($im, 255, 255, 255); 
$grey = imagecolorallocate($im, 128, 128, 128); 
$black = imagecolorallocate($im, 0, 0, 0); 
imagefilledrectangle($im, 0, 0, 399, 29, $white); 

// The text to draw 
$text = 'Testing'; 
// Replace path by your own font path 
$font = 'arial.ttf'; 

// Add some shadow to the text 
imagettftext($im, 20, 0, 11, 21, $grey, 'arial.ttf', $text); 

// Add the text 
imagettftext($im, 20, 0, 10, 20, $black, 'arial.ttf', $text); 

// Using imagepng() results in clearer text compared with imagejpeg() 
imagepng($im); 
imagedestroy($im); 
?> 

परिणाम:http://www.7679679.com/app/test-ansi.php

+0

आप हेडर सेट करते हैं ... बस imagepng से पहले, क्या ERRORMSG आप मिलता है पाने के लिए? – michi

+0

क्या php आपको कोई त्रुटि/सूचना देता है? 'Imagettftext' फ़ंक्शन वापस क्या करता है? यह अंक की सरणी या त्रुटि पर गलत लौटा देना चाहिए। '$ text_result = imagettftext (...) आज़माएं; अगर ($ text_result === झूठा) {echo ("ERROR");} अन्यथा print_r ($ text_result); '। एक और बात, जब आप अपनी नई बनाई गई छवि भर रहे हों, तो आपने ऊंचाई पर एक पिक्सेल छोड़ा और चौड़ाई पर केवल 2 9 पिक्सेल चौड़ाई भर दी, क्या यह उद्देश्य पर है? – Buksy

+0

आपने उस सरणी को कैसे मुद्रित किया ??? – Saswat

उत्तर

6

सूचना आप नि: शुल्क प्रकार स्थापित नहीं है:

["FreeType Support"]=> 
    bool(false) 

इस फ़ंक्शन को जीडी लाइब्रेरी और »फ्रीटाइप लाइब्रेरी दोनों की आवश्यकता है।

इससे पहले कि आप इस फ़ंक्शन का उपयोग कर सकें, आपको फ्री टाइप लाइब्रेरी इंस्टॉल करने की आवश्यकता होगी।

इन पैकेज को स्थापित करने का प्रयास करें: एस freetype, freetype-devel

आप PHP संकलित यदि आप संकलन समय के दौरान सुनिश्चित करें कि आप सक्षम जोड़ा freetype बना सकते हैं:

--with-freetype-dir=/usr/include/freetype2/ --with-freetype 

या आप कुछ इस तरह का उपयोग कर यदि YUM या APT-GET के रूप में उन पुस्तकालयों को स्थापित करना वास्तव में आसान होना चाहिए, और शुरू करने के साथ एक त्वरित खोज ob google होना चाहिए।

+0

फ़्रीटाइप समर्थन की आवश्यकता PHP मैन्युअल में प्रलेखित है, तो http://php.net/manual/en/function.imagettftext.php देखें और http://php.net/manual/en/function.imagettfbbox.php – dregad

13

एक ही समस्या थी, freetype स्थापित साथ, समाधान

$font = "./Arial.ttf"; // <--- put ./ in front of filename 
+1

यह सबसे अच्छा जवाब लगता है :) – JayKandari

+0

यह मेरे लिए काम किया :) Thx बहुत – kodmanyagha

+1

मेरे लिए काम किया! जबरदस्त हंसी! क्या आप विस्तार से समझा सकते हैं कि यह क्यों काम करता है? –

0

एंड्रयू सही है था, php manual for imagettftext राज्यों freetype imagettftext, imagettfbox, और दूसरों का उपयोग करने के लिए आवश्यक है।अधिकांश लोगों को जी.डी. devel पैकेज स्वचालित रूप से freetype स्थापित हो जाएगा:

फेडोरा/redhat:

yum install gd gd-devel php-gd 

Debian/Ubuntu:

apt-get install php5-gd libgd2-xpm libgd2-xpm-dev 

यह त्रुटि शायद आपके लॉग में था:

PHP Fatal error: Call to undefined function imageTTFText() 
2

अच्छी तरह से मुझे

के आसपास समस्या भी मिली 10
$font='arial.tff'; 

मुझे लगता है कि मैं मान आप एक Windows उपयोगकर्ता हैं आप

$font="c:/windows/fonts/arial.ttf"; 

तरह $ फ़ॉन्ट का निरपेक्ष पथ प्रदान करना चाहिए। और हटाने

header('Content-Type:image/png'); 

वास्तविक त्रुटि