PHP   发布时间:2019-11-13  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了PHP实现批量生成App各种尺寸Logo大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

使用php GD,使用良好,一键剪裁各种尺寸,打包下载。经常换icon的懂的,美工给你一个1024的logo,你得ps出各种尺寸,于是有了这个东西。

核心代码

title"> 代码如下:
source($sourcE); } } /** * set the source image * * @param String|array $source */ public function source($sourcE) { if(!is_array($sourcE)) { $this->source["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,$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,$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,$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,$x,$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,$quality); break; default : imagejpeg($this->image,$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,-3); } return $error; } public function ext() { return $this->ext; } }

以上就是本文所述的全部内容了,希望大家能够喜欢。

大佬总结

以上是大佬教程为你收集整理的PHP实现批量生成App各种尺寸Logo全部内容,希望文章能够帮你解决PHP实现批量生成App各种尺寸Logo所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:生成