2011-12-27 82 views
1

我正在尋找使用PHP將內部陰影添加到文本的方式。我不是在尋找一個包含HTML和/或CSS的解決方案。圖片必須僅使用PHP生成。將內部陰影添加到文本

例如:http://i.imgur.com/jYGvM.png
從上面的文本('原始')我想創建修改文本,所以它會看起來像文本在底部('陰影')。
效果必須只能使用GD庫或Imagemagick來實現,因爲我無法將新庫安裝到服務器。

+0

不熟悉PHP,但你可以做一些在PHP編寫的飛行CSS? – Brian 2011-12-27 16:11:23

回答

0

一種方法是用不同的顏色和小的偏移量繪製文本兩次。

下面是示例代碼,主要取自php manual,並進行了一些修改以使陰影出現。生成的圖像是here

代碼:

<?php 
// Create a 300x100 image 
$im = imagecreatetruecolor(300, 100); 
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); 
$gray = imagecolorallocate($im, 0x55, 0x55, 0x55); 
$gray2 = imagecolorallocate($im, 0xDD, 0xDD, 0xDD); 

// Make the background red 
imagefilledrectangle($im, 0, 0, 299, 99, $gray2); 

// Path to our ttf font file 
$font_file = './ariblk.ttf'; 

// the text without shadow 
imagefttext($im, 40, 0, 10, 45, $white, $font_file, 'Original'); 

// the shadow for "Shadow" 
imagefttext($im, 40, 0, 10, 89, $gray, $font_file, 'Shadow'); 

// and the word itself 
imagefttext($im, 40, 0, 10, 90, $white, $font_file, 'Shadow'); 

// Output image to the browser 
header('Content-Type: image/png'); 

imagepng($im); 
imagedestroy($im); 
?>