使用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;
}
}
以上就是本文所述的全部内容了,希望大家能够喜欢。
PHP,生成,App,Logo
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新动态
- 《庄心妍 实力唱将 发烧音乐精选集》[WAV+CUE][380MB]
- [音展纪念碟]2006年《TAA台湾第十六届国际HI-ENDHI-FI音响展》2cd[WAV]
- 中国音乐地图之听见西藏山歌牧歌酒歌2020[WAV分轨]
- 王宏伟2017-永远的红飘带[太平洋影音][WAV+CUE]
- 费翔.1997-NOW现在【第一中国】【WAV+CUE】
- 新格合唱团.1981-我唱你和2辑(滚石新格民歌系列)【新格】【WAV+CUE】
- 陈柏宇.2011-QUINQUENNIUM【SONY】【WAV+CUE】
- 雨果唱片-《金唛系列-蔷薇依韵琼瑶》WAV
- 陈百强《凝望(2012华纳LPCD45限量版)[DMI]》[WAV整轨]
- 模拟之声慢刻CD《徐小凤45周年》[德国母带][低速原抓WAV+CUE]
- 《庄心妍 实力唱将 发烧音乐精选集》[WAV+CUE][380MB]
- 《王菲 单曲合集》[FlAC/分轨][520MB]
- 《费玉清 原味再现 水长流》[WAV+CUE][430MB]
- 群星.1992-畅销榜老歌金曲10CD【风格】【WAV+CUE】
- 孙悦.2024-时光音乐会【金蜂】【WAV+CUE】