PHP实现圆角图片
工作中用到,自己写了一个,分享给有需要的人,前面是类定义,后面2行是调用。
优点:
不需要外部图片
支持PNG透明
可自定义圆角半径
不足:
只能指定一种透明色
<?php
class RoundedCorner {
private $_r;
private $_g;
private $_b;
private $_image_path;
private $_radius;
function __construct($image_path, $radius, $r = 255, $g = 0, $b = 0) {
$this->_image_path = $image_path;
$this->_radius = $radius;
$this->_r = (int)$r;
$this->_g = (int)$g;
$this->_b = (int)$b;
}
private function _get_lt_rounder_corner() {
$radius = $this->_radius;
$img = imagecreatetruecolor($radius, $radius);
$bgcolor = imagecolorallocate($img, $this->_r, $this->_g, $this->_b);
$fgcolor = imagecolorallocate($img, 0, 0, 0);
imagefill($img, 0, 0, $bgcolor);
imagefilledarc($img, $radius, $radius, $radius*2, $radius*2, 180, 270, $fgcolor, IMG_ARC_PIE);
imagecolortransparent($img, $fgcolor);
return $img;
}
private function _load_source_image() {
$ext = substr($this->_image_path, strrpos($this->_image_path, '.'));
if (empty($ext)) {
return false;
}
switch(strtolower($ext)) {
case '.jpg':
$img = @imagecreatefromjpeg($this->_image_path);
break;
case '.gif':
$img = @imagecreatefromgif($this->_image_path);
break;
case '.png':
$img = @imagecreatefrompng($this->_image_path);
break;
default:
return false;
}
return $img;
}
public function round_it() {
// load the source image
$src_image = $this->_load_source_image();
if ($src_image === false) {
die('Sorry, can\'t load the image');
}
$image_width = imagesx($src_image);
$image_height = imagesy($src_image);
// create a new image, with src_width, src_height, and fill it with transparent color
$image = imagecreatetruecolor($image_width, $image_height);
$trans_color = imagecolorallocate($image, $this->_r, $this->_g, $this->_b
相关文档:
普通PHP程序员笔试题
1. 用PHP打印出前一天的时间,打印格式是2007年5月10日 22:21:21
2. PHP代码如下:
$a="hello";
$b=&$a;
unset($b);
$b="world";
echo $a;
其结果是?
3. PHP代码如下:
$str="cd";
$$str="landog";
$$st ......
用PHP过滤提交表单的html代码里可能有被利用引入外部危险内容的代码。例如,有些时候用户提交表单中含有html内容,但这可能造成显示页面布局混乱,需要过滤掉。
以下是程序代码:
复制代码
function uhtml($str)
{
$farr = array(
......
1、mysql_connect()-建立数据库连接 {3RY4HVT?
格式: Fv n:V\eb
resource mysql_connect([string hostname [:port] [:/path/to/socket] [, string username] [, string password]]) _I;+p eq
例: 1(V>8}zn
$conn = @mysql_connect("localhost", "username", "password") or dir(" ......
[AJAX介绍]
Ajax是使用客户端脚本与Web服务器交换数据的Web应用开发方法。Web页面不用打断交互流程进行重新加裁,就可以动态地更新。使用Ajax,用户可以创建接近本地桌面应用的直接、高可用、更丰富、更动态的Web用户界面。
异步JavaScript和XML(AJAX)不是什么新技术,而是使用几种现有技术——包 ......
void header ( string string [, bool replace [, int http_response_code]] )
void header ( string string [, bool replace [, int http_response_code]] )
header()是用来发送 HTTP Header的。replace是个可选的参数,指示是否替代一个先期相似的header,
......