Php 使用image使用imagettftext设置纹理背景
我可以通过使用Php 使用image使用imagettftext设置纹理背景,php,Php,我可以通过使用imagettftext()函数在PHP中使用GD创建图像。文本的颜色是使用imagecolorallocate()指定的,但它采用RGB格式的颜色 我有一系列纹理图像-每个10 x 10像素。我想使用这些纹理图像作为文本的颜色,而不是单一的RBG颜色 我不知道如何实现这一点,有可能吗?如果可以,请使用。它可以做到这一点,开箱即用 示例来自: 如果可以,请使用。它可以做到这一点,开箱即用 示例来自: 我制作了这个函数,它根据定义的颜色逐像素替换 function imagettft
imagettftext()
函数在PHP中使用GD创建图像。文本的颜色是使用imagecolorallocate()
指定的,但它采用RGB格式的颜色
我有一系列纹理图像-每个10 x 10像素。我想使用这些纹理图像作为文本的颜色,而不是单一的RBG颜色
我不知道如何实现这一点,有可能吗?如果可以,请使用。它可以做到这一点,开箱即用
示例来自:
如果可以,请使用。它可以做到这一点,开箱即用
示例来自:
我制作了这个函数,它根据定义的颜色逐像素替换
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;
}
函数ImageTTftExtrare(&$im、$textureimage、$size、$angle、$\uX、$\uY、$font、$text){
$w=图像X($im);
$h=图像系统($im);
$sz=getimagesize($textureimage);
$tx=null;
开关($sz['mime'])){
案例“image/png”:
$tx=imagecreatefrompng($textureimage);
打破
案例“图像/jpeg”:
$tx=imagecreatefromjpeg($textureimage);
打破
案例“image/gif”:
$tx=imagecreatefromgif($textureimage);
打破
}
//与$im大小相同
$tmp=imagecreatetruecolor($w,$h);
//充满质感
imagesettile($tmp,$tx);
imagefilledrectangle($tmp,0,0,$w,$h,IMG_COLOR_TILED);
//奇怪的颜色
$pink=图像颜色最接近($im,255,0255);
$rect=imagettftext($im,$size,$angle,$\u x,$\u y,$pink,$font,$text);//“减号”用于在无别名的情况下绘制
对于($x=0;$x我制作了这个函数,它根据定义的颜色逐像素替换
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;
}
函数ImageTTftExtrare(&$im、$textureimage、$size、$angle、$\uX、$\uY、$font、$text){
$w=图像X($im);
$h=图像系统($im);
$sz=getimagesize($textureimage);
$tx=null;
开关($sz['mime'])){
案例“image/png”:
$tx=imagecreatefrompng($textureimage);
打破
案例“图像/jpeg”:
$tx=imagecreatefromjpeg($textureimage);
打破
案例“image/gif”:
$tx=imagecreatefromgif($textureimage);
打破
}
//与$im大小相同
$tmp=imagecreatetruecolor($w,$h);
//充满质感
imagesettile($tmp,$tx);
imagefilledrectangle($tmp,0,0,$w,$h,IMG_COLOR_TILED);
//奇怪的颜色
$pink=图像颜色最接近($im,255,0255);
$rect=imagettftext($im,$size,$angle,$\u x,$\u y,$pink,$font,$text);//“减号”用于在无别名的情况下绘制
对于xx=0;$x这是一个Groovy图像。我确实考虑过IMAGE,但我的主机似乎没有它,所以我正在看GD。IVEMAGEK看起来更强大,所以我会看看我是否能得到这个设置。谢谢。这是一个Groovy图像!我确实考虑过IMAGEMGEK,但是我的主机好像没有它,所以我正在看GD。IMAGEoes似乎更强大,所以我会看看我是否能得到这个设置。谢谢。