2016-04-21 15 views
0

Also ich versuche, die GD-Bibliothek in meine Wordpress-Website zu verwenden.imagettftext Funktion in eine Funktion

Ich habe die images.php Seite mit diesem Code erstellt:

function loadImage($name, $lastname) { 

    header ("Content-type: image/jpg"); 

$fond = imagecreatefromjpeg('link'); 

$font = "arial.ttf"; 
$noir = imagecolorallocate($fond, 0, 0, 0); 
$blanc = imagecolorallocate($fond, 255, 255, 255); 


imagettftext($fond, 20, 0, 600, 80, $blanc, $font, $name); 
imagestring($fond, 5, 200, 200, $lastname, $blanc); 
imagejpeg($fond, 'folder'); 
} 

Dann führe ich loadimage ("Bob"); in eine andere Seite. Die Bildzeichenfunktion funktioniert, aber nicht das Bild. Ich habe alles versucht, aber es scheint, dass imagettftext nicht funktioniert, wenn man Argumente für die Anzeige der Zeichenfolge angibt.

Wenn du mir auf, dass ...

Ich glaube, Sie haben alle

Dank

Antwort

0

getan helfen konnte, aber nur Farbe etwas ändern muß, wie:

$fond = imagecreatefromjpeg('link_of_image'); 

$font = "arial.ttf"; 
$noir = imagecolorallocate($fond, 0, 0, 0); 
$blanc = imagecolorallocate($fond, 0, 0, 0); 

imagettftext($fond, 20, 0, 600, 80, $blanc, $font, $name); 

imagestring($fond, 5, 200, 200, $lastname, $blanc); 

header ("Content-type: image/jpg"); 
imagejpeg($fond); 
imagedestroy($fond); 

Aufgrund der weißen Farbe es wird nicht angezeigt.

+0

dass ändert nichts ... Es zeigt nur das Bild ohne Text an. – GreatHawkeye

+0

imagecolorallocate (Ressource $ Bild, int $ rot, int $ grün, int $ blau) Also, $ blanc ist schwarz in Ihrem Code, $ Noir ist weiß so kann es sein, dass Ihr Bild dunkel sein kann, so dass Sie den Text nicht sehen können. probiere ein helles Bild in deinem Code. –

+0

Nein, $ blanc ist in meinem Code weiß: $ blanc = imagecolorallocate ($ fond, 255, 255, 255); – GreatHawkeye

0

Ich habe Ihren Code bearbeitet und jetzt wird es ausgeführt, nur geringfügige Änderung in Parameter von imagettftext.

imagettftext (resource $ Bild, Schwimm $ Größe, float $ Winkel, int $ x, int $ y, int $ color, string $ fontfile, string $ text)

<?php 

    $name='anand'; 
    $lastname='jain'; 
    $fond = imagecreatefromjpeg('https://upload.wikimedia.org/wikipedia/en/9/94/Salisbury_mascotlogo.jpg'); 

    $font = "arial.ttf"; 
    $noir = imagecolorallocate($fond, 0, 0, 0); 
    $blanc = imagecolorallocate($fond, 0, 0, 0); 


    imagestring($fond, 5, 200, 200, $lastname, $blanc); 
    imagettftext($fond, 12, 0, 100, 127, $noir, $font, $name); 


    header ("Content-type: image/jpeg"); 
    imagejpeg($fond); 
    imagedestroy($fond); 

    ?>