茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    PHP實(shí)現(xiàn)批量生成App各種尺寸Logo
    來(lái)源:易賢網(wǎng) 閱讀:1193 次 日期:2015-03-23 14:45:20
    溫馨提示:易賢網(wǎng)小編為您整理了“PHP實(shí)現(xiàn)批量生成App各種尺寸Logo”,方便廣大網(wǎng)友查閱!

    這篇文章主要介紹了PHP實(shí)現(xiàn)批量生成App各種尺寸Logo的方法和示例的核心代碼,非常的簡(jiǎn)單實(shí)用,這里推薦給小伙伴們,有需要的可以參考下。

    使用PHP GD,使用良好,一鍵剪裁各種尺寸,打包下載。經(jīng)常換icon的懂的,美工給你一個(gè)1024的logo,你得ps出各種尺寸,于是有了這個(gè)東西。

    核心代碼

    代碼如下:

    <?php

    class image {

    /**

    * source image

    *

    * @var string|array

    */

    private $source;

    /**

    * temporay image

    *

    * @var file

    */

    private $image;

    private $ext;

    /**

    * erros

    *

    * @var array

    */

    private $error;

    /**

    * construct

    *

    * @param string|array $source

    */

    public function __construct($source = NULL) {

    if($source != NULL) {

    $this->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,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;

    }

    }

    以上就是本文所述的全部?jī)?nèi)容了,希望大家能夠喜歡。

    更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:PHP實(shí)現(xiàn)批量生成App各種尺寸Logo
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報(bào)班

    • 報(bào)班類(lèi)型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專(zhuān)用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)