2016-11-19 34 views
0

圖像沒有顯示,甚至沒有text.I無法找到錯誤。是否有任何需要添加額外的插件或庫文件?如何在PHP中的圖像上寫文本?

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

    // Create Image From Existing File 
    $jpg_image = imagecreatefromjpeg('test.jpg'); 

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

    // Set Path to Font File 
    $font_path = 'typesimp.TTF'; 

    // Set Text to Be Printed On Image 
    $text = "Hello World!!"; 

    // 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); 
?> 

回答

-1

你有沒有添加的內容類型?

//Set the Content Type 
header('Content-type: image/jpeg'); 
+0

是的,上面提到的 – Assasin