2011-12-27 83 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); 
?>