我可以使用GD使用imagettftext()
函數使用PHP創建圖像。文本的顏色是使用imagecolorallocate()
指定的,但這是以RGB格式的顏色。使用imagettftext設置紋理背景
我有一系列紋理圖像 - 每個10 x 10像素。我想將這些紋理圖像用作文本的顏色,而不是單個RBG顏色。
我看不出如何實現這一點,這有可能嗎?
我可以使用GD使用imagettftext()
函數使用PHP創建圖像。文本的顏色是使用imagecolorallocate()
指定的,但這是以RGB格式的顏色。使用imagettftext設置紋理背景
我有一系列紋理圖像 - 每個10 x 10像素。我想將這些紋理圖像用作文本的顏色,而不是單個RBG顏色。
我看不出如何實現這一點,這有可能嗎?
如果可以,請使用ImageMagick。它可以開箱即用。
例如,從examples:
convert -size 800x120 xc:black -font Corsiva -pointsize 100 \
-tile tile_disks.jpg -annotate +20+80 'Psychedelic!' \
-trim +repage -bordercolor black -border 10 funfont_groovy.jpg
我做了這個功能,根據定義的顏色
function imagettftexture(&$im,$textureimage, $size, $angle, $_x, $_y, $font, $text){
$w = imagesx($im);
$h = imagesy($im);
$sz = getimagesize($textureimage);
$tx = null;
switch($sz['mime']){
case 'image/png':
$tx = imagecreatefrompng($textureimage);
break;
case 'image/jpeg':
$tx = imagecreatefromjpeg($textureimage);
break;
case 'image/gif':
$tx = imagecreatefromgif($textureimage);
break;
}
//same size as $im
$tmp = imagecreatetruecolor($w,$h);
//fill with texture
imagesettile($tmp,$tx);
imagefilledrectangle($tmp, 0, 0, $w, $h, IMG_COLOR_TILED);
//a weird color
$pink = imagecolorclosest($im,255,0,255);
$rect = imagettftext($im,$size,$angle,$_x,$_y,-$pink,$font,$text); // "minus" to draw without aliasing
for($x=0;$x<$w;$x++){
$x = $x;
for($y=0;$y<$h;$y++){
$tmpcolor = imagecolorat($tmp,$x,$y);
$color = imagecolorat($im,$x,$y);
if($color == $pink)
imagesetpixel($im,$x,$y,$tmpcolor);
}
}
//useful to return same value as imagettftext
return $rect;
}
它是相當緩慢的,花了
由像素替換像素100ms處理350x127圖像
760ms來處理1024x342圖像
還有其他的解決方案here
這是一個時髦的形象!我確實考慮過ImageMagick,但我的主機似乎沒有可用,所以我在看GD。 ImageMagick確實看起來更強大,所以我會看看我是否可以得到這個設置。謝謝。 – Chris