2011-05-22 22 views
6

example from php.net का उपयोग करके मुझे एक चेतावनी मिलती है, और छवि सही ढंग से प्रस्तुत नहीं की जाती है। मैं तो जैसे .ttf फाइल करने के लिए एक पूर्ण पथ की आपूर्ति: /var/www/public/myfont.ttfimagettftext फ़ॉन्ट फ़ाइल नहीं खोल सकता

PHP Warning: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Could not find/open font in <phpfile> 

मैं एक कस्टम का उपयोग कर रहा .ttf फ़ॉन्ट here पाया। मैं उबंटू में फ़ाइल को ठीक फ़ॉन्ट फ़ाइल के रूप में खोल सकता हूं। मैंने एक ही परिणाम के साथ अन्य फोंट का भी प्रयास किया।

मैं अपाचे 2, php5, freetype6 और php5-gd के साथ उबंटू 10.04 एलटीएस 32 बिट का उपयोग कर रहा हूं। मैंने उसी परिणाम के साथ, ttf फ़ाइल के साथ 777 फ़ाइल और फ़ोल्डर को chmod करने का भी प्रयास किया।

कस्टम टीटीएफ फ़ॉन्ट फ़ाइल का उपयोग करके मैं उदाहरण कैसे प्राप्त कर सकता हूं?

* संपादित करें: कोड मैं उपयोग कर रहा हूँ: phpinfo से

<?php 
// File is: /var/www/public/test.php 
// Apart from $font variable, it's copy-pasted from php.net 

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

// Create the image 
$im = imagecreatetruecolor(400, 30); 

// 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 = '/var/www/public/UnmaskedBB.ttf'; 

// Add some shadow to the text 
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text); 

// Add the text 
imagettftext($im, 20, 0, 10, 20, $black, $font, $text); 

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

आउटपुट();

[gd] 
GD Support enabled 
GD Version 2.0 
FreeType Support enabled 
FreeType Linkage with freetype 
FreeType Version 2.3.11 
T1Lib Support enabled 
GIF Read Support enabled 
GIF Create Support enabled 
JPEG Support enabled 
libJPEG Version  6b 
PNG Support  enabled 
libPNG Version 1.2.42 
WBMP Support enabled 

परीक्षण is_file और is_readable:

$font = realpath('./').'/UnmaskedBB.ttf'; 
echo "Font: ".$font; // /var/www/public/UnmaskedBB.ttf 
echo "Is file? ".is_file($font); // 1 
echo "Is readable? ".is_readable($font); // 1 
+1

क्या आप सही कोड दिखा सकते हैं? मैं कुछ भी गलत नहीं देख सकता लेकिन पूर्णता के लिए –

+0

क्या आप 100% सुनिश्चित हैं कि फ़ॉन्ट का सटीक पथ है? खाता केस संवेदनशीलता लेना? –

+1

और ऐसा लगता है कि एक टाइपो: 'tff' –

उत्तर

0

उन्नयन सभी php संकुल सहित distro, समस्या हल हो जाती

0

अपने php फ़ाइल के रूप में एक ही निर्देशिका में ttf फ़ाइल ले जाने की कोशिश करो और बदल $ फ़ॉन्ट को

$font = 'UnmaskedBB.ttf'; 
+0

यह पहले से ही नहीं है एक ही निर्देशिका, और मुझे लगता है कि आप .ttf के बिना 'UnmaskedBB' का मतलब है क्योंकि कोई अग्रणी '/' जगह नहीं है? किसी भी मामले में - एक ही चेतावनी मौजूद है –

+0

हां मेरा मतलब है कि, जैसा कि आप मानते हैं ... क्या आप अपनी जीडी लाइब्रेरी को अपडेट करने का प्रयास कर सकते हैं - मेरा बंडल किया गया है (2.0.34 संगत) और ठीक काम करता है। – T1000

8

आप की कोशिश कर सकते सम्मिलित करें:

putenv('GDFONTPATH=' . realpath('.')); 

पहले imagettftext के सामने, बस यह सुनिश्चित करने के लिए कि यह कोई पथ समस्या नहीं है।

अद्यतन

मामले में आप fc-cache तरह फ़ॉन्ट कैश का उपयोग कर रहे हैं, मत भूलना यह ताज़ा करने के लिए, जैसे:

sudo fc-cache -f -v 
+0

दुर्भाग्य से यह वही परिणाम देता है।लेकिन किसी भी मामले में मैं एक स्थिर फ़ॉन्ट फ़ाइल का उपयोग कर रहा हूं, एक में निर्मित नहीं। –

+0

में एक ही समस्या थी और यह मेरे distro (उबंटू 11.10) – Salandur

+2

पर काम करता है यह मेरे लिए काम करता है: putenv ('GDFONTPATH ​​='। Realpath ('।')); उबंटू 12.04 सर्वर का उपयोग कर रहा हूं और यह imagettftext() की समस्या को ठीक करता है: फ़ॉन्ट त्रुटि संदेश नहीं ढूंढ सका। – Grant

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