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
相关文档:
1查找字符位置函数:
strpos($str,search,[int]):查找search在$str中的第一次位置从int开始;
stripos($str,search,[int]):函数返回字符串在另一个字符串中第一次出现的位置。该函数对大小写不敏感
strrpos($str,search,[int]):查找search在$str中的最后一次出现的位置从int
2、提取子字符函数(双字节)
subm ......
本实例只利用到JQuery类库本身的函数和功能,不需要第三方插件的支持。另外,所有表单信息都是利用PHPMailer类库邮件的形式发送给管理员。如果你对JQuery的基本语法还不是很熟悉,请搜索本站的教程资源。如果你对PHPMailer用法不熟悉,请查看本站的另一篇文章《使用PHPMailer类库发送电子邮件》。
第一步,创建一个表单HTM ......
用PHP过滤提交表单的html代码里可能有被利用引入外部危险内容的代码。例如,有些时候用户提交表单中含有html内容,但这可能造成显示页面布局混乱,需要过滤掉。
以下是程序代码:
复制代码
function uhtml($str)
{
$farr = array(
......
global定义一个全局变量,这个全局变量不是应用整个网站,而是应用与当前页面(包括require和include文件)文件。
$aa="test";
function test()
{
global $aa;
echo $aa;
}
test(); //print test
函数内定义的变量函数外可以调用,在函数外定义的的变量函数内不能使用。
gl ......