PHP处理简单图片的颜色填充(0 位领导批示)

原问题地址: http://bbs.blueidea.com/viewthread.php?tid=2956421


现在有一张背景色为纯蓝色(或者红色等) 并且与照片里人物有很明显的反差色彩 的一寸单人照照片,现想把,该图片中的蓝色背景用PHP处理为白色。即类似于PS中,用白色填充蓝色的效果。

使用GD库的imagecolorset函数可以修改简单的索引色. 不过只能对gif与png图片有效

1
2
3
4
5
6
7
8
<?php
$img = file_get_contents('http://home.blueidea.com/attachment/200911/9/207382_1257738485WdvH.gif');
$im = imagecreatefromstring($img);
$bg = imagecolorat($im, 0, 0);
imagecolorset($im, $bg, 0, 0, 255);
imagepng($im);
imagedestroy($im);
?>

[备忘]安装PHP扩展时需要同时安装的扩展列表(0 位领导批示)

仅备忘

php_curl.dll CURL, Client URL library functions Requires: libeay32.dll, ssleay32.dll (bundled)
php_domxml.dll DOM XML functions PHP <= 4.2.0 requires: libxml2.dll
(bundled) PHP >= 4.3.0 requires: iconv.dll (bundled)
php_fdf.dll FDF: Forms Data Format functions. Requires: fdftk.dll
gnu_gettext.dll (bundled), PHP >= 4.2.3 requires libintl-1.dll,
php_iconv.dll ICONV characterset conversion Requires: iconv-1.3.dll
php_ingres.dll Ingres II functions Requires: Ingres II libraries
php_interbase.dll InterBase functions Requires: gds32.dll (bundled)
php_java.dll Java functions PHP <= 4.0.6 requires: jvm.dll (bundled)
php_ldap.dll LDAP functions PHP <= 4.2.0 requires libsasl.dll(bundled),
PHP >= 4.3.0 requires libeay32.dll,ssleay32.dll (bundled)
php_mcrypt.dll Mcrypt Encryption functions Requires: libmcrypt.dll
php_mhash.dll Mhash functions PHP >= 4.3.0 requires: libmhash.dll (bundled)
php_mcrypt.dll Mcrypt Encryption functions Requires: libmcrypt.dll
php_mhash.dll Mhash functions PHP >= 4.3.0 requires: libmhash.dll (bundled)
php_msql.dll mSQL functions Requires: msql.dll (bundled)
php_mssql.dll MSSQL functions Requires: ntwdblib.dll (bundled)
php_mysql.dll MySQL functions PHP >= 5.0.0, requires libmysql.dll (bundled)
php_mysqli.dll MySQLi functions PHP >= 5.0.0, requires libmysqli.dll (bundled)
php_oci8.dll Oracle 8 functions Requires: Oracle 8.1+ client libraries
php_openssl.dll OpenSSL functions Requires: libeay32.dll (bundled)
php_oracle.dll Oracle functions Requires: Oracle 7 client libraries
php_sybase_ct.dll Sybase functions Requires: Sybase client libraries
php_xmlrpc.dll XML-RPC functions PHP >= 4.2.1 requires: iconv.dll (bundled)
php_xslt.dll XSLT functions PHP <= 4.2.0 requires sablot.dll, expat.dll (bundled).
PHP >= 4.2.1 requires sablot.dll, expat.dll, iconv.dll (bundled).

转换avatar头像函数(0 位领导批示)

仅备忘

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
 * 获取 avatar 头像
 *
 * @param string $email
 * @param integer $size
 * @return string
 */
function getAvatar($email, $size = '24')
{
	if (!is_numeric($size))
	{
		$size = '24';
	}
	if (!empty($email))
	{
		$out = 'http://www.gravatar.com/avatar/' . md5(strtolower($email)) . '?s=' . $size;
		$avatar = "<img src='{$out}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' alt='{$email}' /> " . $email;
	}
	else
	{
		$avatar = $email;
	}
 
	return $avatar;
}

[备忘]PHP无法加载LDAP扩展的解决方法(2 位领导批示)

最近的项目中需要使用域账号访问域控服务器. 要开启PHP的LDAP扩展.

打开php.ini后去掉 ;extension=php_ldap.dll 的分页.重启APACHE.
刷新页面..显示 Call to undefined function ldap_connect()

0_o 咋回事捏? 打开PHPINFO发现没有 LDAP.. 说明木有加载上..

最终找到解决方法:


将PHP目录下的libeay32.dll和ssleay32.dll拷贝到system32目录下.重启APACHE

搞电.. (^_^)

将指定的数组元素排在数组最后(0 位领导批示)

原题目地址: http://bbs.blueidea.com/thread-2953135-1-1.html

我的解法是删除那个数组元素再将array_push那个元素

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
function moveArrayElement(& $arr, $element)
{
    foreach($arr as $key => $value)
    {
        if($value == $element)
        {
            unset($arr[$key]);
        }
    }
    array_push($arr, $element);
}
$arr = array('楼主', '沙发', '板凳', '地板');
moveArrayElement($arr, '楼主');
print_r($arr);
?>

全文阅读 »

数组脏话查找关键字问题(4 位领导批示)

原问题地址: http://bbs.blueidea.com/thread-2948905-1-1.html


我想在数组含有“中国|||我国|||大地”,当有一句话同时出现“中国,我国,大地”时就提示有脏话,其他的如“ [2] => sex”就直接提示提示有脏话,这样数组怎样查找啊!大大们,出来帮我看看吧

我的解决方法. 思路是遍历数组进行逐个比较.

全文阅读 »

[备忘]Zend Studio for Eclipse 代码格式化(5 位领导批示)

使用方法:

打开 Window -> Preferences -> PHP -> Formatter 选择 Import 导入 xml 文件即可

全文阅读 »

正则表达式子模式使用函数(1 位领导批示)

原问题地址: http://bbs.blueidea.com/thread-2944055-1-1.html

比较正确的解决方法:

1
2
3
4
5
<?php
$str="[thunder]ftp://3gset.cn:3gset@down.3gset.cn/谢谢你的温柔-S.H.E_飞轮海.mv.320x240.avi[/thunder]";
$str = preg_replace("/\[thunder\](.[^\[]*)\[\/thunder\]/ie","'<a href=\"thunder://'.base64_encode('\\1').'\">\\1</a>'", $str);
echo htmlspecialchars($str);
?>

这段代码的重点是使用了修饰符 e
正则表达式的修饰符 e 是这么解释的:
如果设置这个修饰符, preg_replace() 将在替换值里进行正常的涉及到 的替换, 等同于在 PHP 代码里面一样, 然后用于替换搜索到的字符串.

全文阅读 »

PHP创建文件重名.重新命名文件算法(0 位领导批示)

原问题: http://bbs.blueidea.com/thread-2942989-1-1.html

随便写了一个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
function createFile($filename, $content = '')
{
    $fp = file_put_contents($filename, $content);
}
 
// 要创建的文件名称
$filename = 'www.txt';
 
if(file_exists($filename))
{
    // 打开当前目录
   $handle = opendir('./');
    $fileinfo = pathinfo($filename);
    //print_r($fileinfo);
    $files = array();
    while (false !== ($file = readdir($handle)))
    {
        if(preg_match_all("/{$fileinfo['filename']}(\d*)\.{$fileinfo['extension']}/i", $file, $match))
        {
            $max = max($match[1]);
            if($max)
            {
                $createfile = $fileinfo['filename'] . ($max + 1) . '.' . $fileinfo['extension'];
            }
            else
            {
                $createfile = $fileinfo['filename'] . '1.' . $fileinfo['extension'];
            }
        }
    }
    createFile($createfile);
}
else
{
    createFile($filename);
}
?>

另一种思路..使用临时文件作记数器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
function createFile($filename, $content = '')
{
    if(file_exists($filename . '.tmp'))
    {
        $num = (int) file_get_contents($filename . '.tmp') + 1;
        $fileinfo = pathinfo($filename);
        file_put_contents($fileinfo['filename'] . '(' . $num . ')' .$fileinfo['extension'], $content);
        file_put_contents($filename . '.tmp', $num);
    }
    else
    {
        file_put_contents($filename, $content);
        file_put_contents($filename . '.tmp', 1);
    }
}
createFile('test.txt');
?>

[原]WordPress 评论表情插件 silver smilies v0.2 发布(38 位领导批示)

终于有时间更新表情插件了(查看 silver smilies v0.1)

修改了部分方法. 表情直接从目录中读取.所以现在可以方便的增减表情图片了.只需把图片放入face目录即可.不过暂时还不支持中文图片名称.

其它的都很简单.自己看吧^_^

Download

效果预览:

silver_smilies_0_2

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志