使用PHP GD,使用良好,一键剪裁各种尺寸,打包下载。经常换icon的懂的,美工给你一个1024的logo,你得ps出各种尺寸,于是有了这个东西。
核心代码
复制代码 代码如下:
<"name"] = $source;
$this->source["tmp_name"] = $source;
$type = NULL;
$ext = strtolower(end(explode(".",$source)));
switch($ext) {
case "jpg" :
case "jpeg" : $type = "image/jpeg"; break;
case "gif" : $type = "image/gif"; break;
case "png" : $type = "image/png"; break;
}
$this->source["type"] = $type;
} else {
$this->source = $source;
}
$this->destination = $this->source["name"];
}
/**
* resize the image
*
* @param int $width
* @param int $height
*/
public function resize($width = NULL,$height = NULL) {
if(isset($this->source["tmp_name"]) && file_exists($this->source["tmp_name"])) {
list($source_width,$source_height) = getimagesize($this->source["tmp_name"]);
if(($width == NULL) && ($height != NULL)) {
$width = ($source_width * $height) / $source_height;
}
if(($width != NULL) && ($height == NULL)) {
$height = ($source_height * $width) / $source_width;
}
if(($width == NULL) && ($height == NULL)) {
$width = $source_width;
$height = $source_height;
}
switch($this->source["type"]) {
case "image/jpeg" : $created = imagecreatefromjpeg($this->source["tmp_name"]); break;
case "image/gif" : $created = imagecreatefromgif($this->source["tmp_name"]); break;
case "image/png" : $created = imagecreatefrompng($this->source["tmp_name"]); break;
}
$this->image = imagecreatetruecolor($width,$height);
imagecopyresampled($this->image,$created,0,0,0,0,$width,$height,$source_width,$source_height);
}
}
/**
* add watermark on image
*
* @param string $mark
* @param int $opac
* @param int $x_pos
* @param int $y_pos
*/
public function watermark($mark,$opac,$x_pos,$y_pos) {
if(file_exists($mark) && ($this->image != "")) {
$ext = strtolower(end(explode(".",$mark)));
switch($ext) {
case "jpg" :
case "jpeg" : $watermark = imagecreatefromjpeg($mark); break;
case "gif" : $watermark = imagecreatefromgif($mark); break;
case "png" : $watermark = imagecreatefrompng($mark); break;
}
list($watermark_width,$watermark_height) = getimagesize($mark);
$source_width = imagesx($this->image);
$source_height = imagesy($this->image);
if($x_pos == "top") $pos = "t"; else $pos = "b";
if($y_pos == "left") $pos .= "l"; else $pos .= "r";
$dest_x = 0;
$dest_y = 0;
switch($pos) {
case "tr" : $dest_x = $source_width - $watermark_width; break;
case "bl" : $dest_y = $source_height - $watermark_height; break;
case "br" : $dest_x = $source_width - $watermark_width; $dest_y = $source_height - $watermark_height; break;
}
imagecopymerge($this->image,$watermark,$dest_x,$dest_y,0,0,$watermark_width,$watermark_height,$opac);
}
}
/**
* crop the image
*
* @param int $x
* @param int $y
* @param int $width
* @param int $height
*/
public function crop($x,$y,$width,$height) {
if(isset($this->source["tmp_name"]) && file_exists($this->source["tmp_name"]) && ($width > 10) && ($height > 10)) {
switch($this->source["type"]) {
case "image/jpeg" : $created = imagecreatefromjpeg($this->source["tmp_name"]); break;
case "image/gif" : $created = imagecreatefromgif($this->source["tmp_name"]); break;
case "image/png" : $created = imagecreatefrompng($this->source["tmp_name"]); break;
}
$this->image = imagecreatetruecolor($width,$height);
imagecopy($this->image,$created,0,0,$x,$y,$width,$height);
}
}
/**
* create final image file
*
* @param string $destination
* @param int $quality
*/
public function create($destination,$quality = 100) {
if($this->image != "") {
$extension = substr($destination,-3,3);
switch($extension) {
case "gif" :
imagegif($this->image,$destination,$quality);
break;
case "png" :
$quality = ceil($quality/10) - 1;
imagepng($this->image,$destination,$quality);
break;
default :
imagejpeg($this->image,$destination,$quality);
break;
}
}
}
/**
* check if extension is valid
*
*/
public function validate_extension() {
if(isset($this->source["tmp_name"]) && file_exists($this->source["tmp_name"])) {
$exts = array("image/jpeg", "image/pjpeg", "image/png", "image/x-png");
$ext = $this->source["type"];
$valid = 0;
$this->ext = '.not_found';
if ($ext == $exts[0] || $ext == $exts[1]) {
$valid = 1;
$this->ext = '.jpg';
}
// if ($ext == $exts[2]) {
// $valid = 1;
// $this->ext = '.gif';
// }
if ($ext == $exts[2] || $ext == $exts[3]) {
$valid = 1;
$this->ext = '.png';
}
if($valid != 1) {
$this->error .= "extension";
}
} else {
$this->error .= "source";
}
}
/**
* check if the size is correct
*
* @param int $max
*/
public function validate_size($max) {
if(isset($this->source["tmp_name"]) && file_exists($this->source["tmp_name"])) {
$max = $max * 1024;
if($this->source["size"] >= $max) {
$this->error .= "size";
}
} else {
$this->error .= "source";
}
}
/**
* check if the dimension is correct
*
* @param int $limit_width
* @param int $limit_height
*/
public function validate_dimension($limit_width,$limit_height) {
if(isset($this->source["tmp_name"]) && file_exists($this->source["tmp_name"])) {
list($source_width,$source_height) = getimagesize($this->source["tmp_name"]);
if(($source_width > $limit_width) || ($source_height > $limit_height)) {
$this->error .= "dimension";
}
} else {
$this->error .= "source";
}
}
/**
* get the found errors
*
*/
public function error() {
$error = array();
if(stristr($this->error,"source")) $error[] = "找不到上传文件";
if(stristr($this->error,"dimension")) $error[] = "上传图片尺寸太大";
if(stristr($this->error,"extension")) $error[] = "不符合要求的格式";
if(stristr($this->error,"size")) $error[] = "图片文件太大";
return $error;
}
public function error_string() {
$error = "";
if(stristr($this->error,"source")) $error .= "找不到上传文件 / ";
if(stristr($this->error,"dimension")) $error .= "上传图片尺寸太大 / ";
if(stristr($this->error,"extension")) $error .= "不符合要求的格式 / ";
if(stristr($this->error,"size")) $error .= "图片文件太大 / ";
if(eregi(" / $", $error)) {
$error = substr($error, 0, -3);
}
return $error;
}
public function ext() {
return $this->ext;
}
}
以上就是本文所述的全部内容了,希望大家能够喜欢。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
- 好薇2024《兵哥哥》1:124K黄金母盘[WAV+CUE]
- 胡歌.2006-珍惜(EP)【步升大风】【FLAC分轨】
- 洪荣宏.2014-拼乎自己看【华特】【WAV+CUE】
- 伊能静.1999-从脆弱到勇敢1987-1996精选2CD【华纳】【WAV+CUE】
- 刘亮鹭《汽车DJ玩主》[WAV+CUE][1.1G]
- 张杰《最接近天堂的地方》天娱传媒[WAV+CUE][1.1G]
- 群星《2022年度发烧天碟》无损黑胶碟 2CD[WAV+CUE][1.4G]
- 罗文1983-罗文甄妮-射雕英雄传(纯银AMCD)[WAV+CUE]
- 群星《亚洲故事香港纯弦》雨果UPMAGCD2024[低速原抓WAV+CUE]
- 群星《经典咏流传》限量1:1母盘直刻[低速原抓WAV+CUE]
- 庾澄庆1993《老实情歌》福茂唱片[WAV+CUE][1G]
- 许巍《在别处》美卡首版[WAV+CUE][1G]
- 林子祥《单手拍掌》华纳香港版[WAV+CUE][1G]
- 郑秀文.1997-我们的主题曲【华纳】【WAV+CUE】
- 群星.2001-生命因爱动听电影原创音乐AVCD【MEDIA】【WAV+CUE】