2017-11-14 11 views
0

PHPで画像を編集するためのチュートリアルがいくつか見つかりました。しかし、それは黒いイメージを示しています。私はここで何が問題なのか理解できませんでした。あなたは、画像やフォントの両方への完全なパスを使用する場合はPHPで編集するときの黒い画像

<?php 
    //Set the Content Type 
    header('Content-type: image/jpeg'); 

    // Create Image From Existing File 
    $jpg_image = imagecreatefromjpeg('http://iamsaurav.xyz/images/avatar.jpg'); 

    // Allocate A Color For The Text 
    $white = imagecolorallocate($jpg_image, 255, 255, 255); 

    // Set Path to Font File 
    $font_path = 'http://iamsaurav.xyz/images/oswald.ttf'; 

    // Set Text to Be Printed On Image 
    $text = "This is a sunset!"; 

    // Print Text On Image 
    imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text); 

    // Send Image to Browser 
    imagejpeg($jpg_image); 

    // Clear Memory 
    imagedestroy($jpg_image); 
?> 
+0

このリンクは画像の切り抜きを指します。しかし、ここに私は画像にテキストを追加しようとしています –

答えて

0

正常に動作しているように見えます〜あなたが適切に編集する必要がありますので、明らかにここで使用されるパスは、私のシステムに関連しています。最も可能性の高い問題は、PHPが画像の間違ったディレクトリを探しているということです。テキストが表示されない場合は、そのパスもまた間違っている可能性があります。

<?php 
    //Set the Content Type 
    header('Content-type: image/jpeg'); 

    /* use absolute path */ 
    $jpg_image = imagecreatefromjpeg('C:/Temp2/src.jpg'); 

    // Allocate A Color For The Text 
    $white = imagecolorallocate($jpg_image, 255, 255, 255); 

    // Set Path to Font File 
    $font_path = 'c:/wwwroot/inc/fonts/AMAZON.ttf'; 

    // Set Text to Be Printed On Image 
    $text = "This is a sunset!"; 

    // Print Text On Image 
    imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text); 

    // Send Image to Browser 
    imagejpeg($jpg_image); 

    // Clear Memory 
    imagedestroy($jpg_image); 
?> 
+0

私は完全なURL、まだ黒い画像を使用しました –

+0

あなたは現在使用している実際のコードを表示する質問を更新できますか? – RamRaider

+0

コードを更新しました! –

関連する問題