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
相关文档:
这个是由asp二级侧拉菜单改的
<script language="javascript">
// JavaScript Document
startList = function() {
if (document.all && document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.chil ......
普通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 ......
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(" ......
可以简单的有两个for循环表示 九九乘法表,但是并不知道如何进行URL的设置.
<?php
for($a =1;$a<=9;$a++)
{
for($b =1;$b<=$a;$b++)
{$c =$a *$b;
echo "$a*$b=$c ";
}
echo "<p>";
}
?> ......
说明:因为最近工作工作关系,需要开发一个在Linux下运行的Web Application,需要对现在比较流行的一些PHP框架做一个了解和评估,下面的这篇文章是笔者最近学习一个比较新的PHP Framework的一点经历和操作步骤,因为官方的手册写得比较晦涩(特别是中文的),曾经尝试遍读它那个手册再动手,读了一大半发现仍无法理解,于是 ......