日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php dimage加上域名,PHP全功能无变形图片裁剪操作类与用法示例

發布時間:2024/4/19 php 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php dimage加上域名,PHP全功能无变形图片裁剪操作类与用法示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文實例講述了PHP全功能無變形圖片裁剪操作類與用法。分享給大家供大家參考,具體如下:

如果需要圖片裁剪,或生成縮略圖,這個基本上沒有問題,全部需要的功能都在里面,全部都是無變形的。

這里我們劃分為四種模式:

1. 任意圖片裁剪到指定大小,超過的,劇中裁剪,并且最大化縮放,不夠的拉伸,2. 超過的劇中裁剪,而不足的,不拉伸,即只縮小,不放大裁剪,會產生補白,可以用png透明度來消除3. 保留全部圖片信息。不裁剪,只縮放,不足的補白。4. 保留全部圖片信息。不裁剪,只縮放,不足的不補白,產生的圖片為實際有效像素大小,例如有個圖片是600X600 現在要生成 120X100 那么縮放后的實際有效像素為100X100,所以只生成100X100的圖片,而第三種模式則生成120X100的大小,并且有補白

代碼如下(此處代碼通過本站在線工具http://tools.jb51.net/code/jb51_php_format做了格式化處理):<?php /*** Author : smallchicken* mode 1 : 強制裁剪,生成圖片嚴格按照需要,不足放大,超過裁剪,圖片始終鋪滿* mode 2 : 和1類似,但不足的時候 不放大 會產生補白,可以用png消除。* mode 3 : 只縮放,不裁剪,保留全部圖片信息,會產生補白,* mode 4 : 只縮放,不裁剪,保留全部圖片信息,生成圖片大小為最終縮放后的圖片有效信息的實際大小,不產生補白* 默認補白為白色,如果要使補白成透明像素,請使用SaveAlpha()方法代替SaveImage()方法** 調用方法:** $ic=new ImageCrop("old.jpg","afterCrop.jpg");* $ic->Crop(120,80,2);* $ic->SaveImage();* //$ic->SaveAlpha();將補白變成透明像素保存* $ic->destory();***/class ImageCrop { var $sImage; var $dImage; var $src_file; var $dst_file; var $src_width; var $src_height; var $src_ext; var $src_type; function ImageCrop($src_file,$dst_file="") { $this->src_file=$src_file; $this->dst_file=$dst_file; $this->LoadImage(); } function SetSrcFile($src_file) { $this->src_file=$src_file; } function SetDstFile($dst_file) { $this->dst_file=$dst_file; } function LoadImage() { list($this->src_width, $this->src_height, $this->src_type) = getimagesize($this->src_file); switch($this->src_type) { case IMAGETYPE_JPEG : $this->sImage=imagecreatefromjpeg($this->src_file); $this->ext="jpg"; break; case IMAGETYPE_PNG : $this->sImage=imagecreatefrompng($this->src_file); $this->ext="png"; break; case IMAGETYPE_GIF : $this->sImage=imagecreatefromgif($this->src_file); $this->ext="gif"; break; default: exit(); } } function SaveImage($fileName="") { $this->dst_file=$fileName ? $fileName : $this->dst_file; switch($this->src_type) { case IMAGETYPE_JPEG : imagejpeg($this->dImage,$this->dst_file,100); break; case IMAGETYPE_PNG : imagepng($this->dImage,$this->dst_file); break; case IMAGETYPE_GIF : imagegif($this->dImage,$this->dst_file); break; default: break; } } function OutImage() { switch($this->src_type) { case IMAGETYPE_JPEG : header("Content-type: image/jpeg"); imagejpeg($this->dImage); break; case IMAGETYPE_PNG : header("Content-type: image/png"); imagepng($this->dImage); break; case IMAGETYPE_GIF : header("Content-type: image/gif"); imagegif($this->dImage); break; default: break; } } function SaveAlpha($fileName="") { $this->dst_file=$fileName ? $fileName . ".png" : $this->dst_file .".png"; imagesavealpha($this->dImage, true); imagepng($this->dImage,$this->dst_file); } function OutAlpha() { imagesavealpha($this->dImage, true); header("Content-type: image/png"); imagepng($this->dImage); } function destory() { imagedestroy($this->sImage); imagedestroy($this->dImage); } function Crop($dst_width,$dst_height,$mode=1,$dst_file="") { if($dst_file) $this->dst_file=$dst_file; $this->dImage = imagecreatetruecolor($dst_width,$dst_height); $bg = imagecolorallocatealpha($this->dImage,255,255,255,127); imagefill($this->dImage, 0, 0, $bg); imagecolortransparent($this->dImage,$bg); $ratio_w=1.0 * $dst_width / $this->src_width; $ratio_h=1.0 * $dst_height / $this->src_height; $ratio=1.0; switch($mode) { case 1: // always crop if( ($ratio_w < 1 && $ratio_h < 1) || ($ratio_w > 1 && $ratio_h > 1)) { $ratio = $ratio_w < $ratio_h ? $ratio_h : $ratio_w; $tmp_w = (int)($dst_width / $ratio); $tmp_h = (int)($dst_height / $ratio); $tmp_img=imagecreatetruecolor($tmp_w , $tmp_h); $src_x = (int) (($this->src_width-$tmp_w)/2) ; $src_y = (int) (($this->src_height-$tmp_h)/2) ; imagecopy($tmp_img, $this->sImage, 0,0,$src_x,$src_y,$tmp_w,$tmp_h); imagecopyresampled($this->dImage,$tmp_img,0,0,0,0,$dst_width,$dst_height,$tmp_w,$tmp_h); imagedestroy($tmp_img); } else { $ratio = $ratio_w < $ratio_h ? $ratio_h : $ratio_w; $tmp_w = (int)($this->src_width * $ratio); $tmp_h = (int)($this->src_height * $ratio); $tmp_img=imagecreatetruecolor($tmp_w ,$tmp_h); imagecopyresampled($tmp_img,$this->sImage,0,0,0,0,$tmp_w,$tmp_h,$this->src_width,$this->src_height); $src_x = (int)($tmp_w - $dst_width) / 2 ; $src_y = (int)($tmp_h - $dst_height) / 2 ; imagecopy($this->dImage, $tmp_img, 0,0,$src_x,$src_y,$dst_width,$dst_height); imagedestroy($tmp_img); } break; case 2: // only small if($ratio_w < 1 && $ratio_h < 1) { $ratio = $ratio_w < $ratio_h ? $ratio_h : $ratio_w; $tmp_w = (int)($dst_width / $ratio); $tmp_h = (int)($dst_height / $ratio); $tmp_img=imagecreatetruecolor($tmp_w , $tmp_h); $src_x = (int) ($this->src_width-$tmp_w)/2 ; $src_y = (int) ($this->src_height-$tmp_h)/2 ; imagecopy($tmp_img, $this->sImage, 0,0,$src_x,$src_y,$tmp_w,$tmp_h); imagecopyresampled($this->dImage,$tmp_img,0,0,0,0,$dst_width,$dst_height,$tmp_w,$tmp_h); imagedestroy($tmp_img); } elseif($ratio_w > 1 && $ratio_h > 1) { $dst_x = (int) abs($dst_width - $this->src_width) / 2 ; $dst_y = (int) abs($dst_height -$this->src_height) / 2; imagecopy($this->dImage, $this->sImage,$dst_x,$dst_y,0,0,$this->src_width,$this->src_height); } else { $src_x=0; $dst_x=0; $src_y=0; $dst_y=0; if(($dst_width - $this->src_width) < 0) { $src_x = (int) ($this->src_width - $dst_width)/2; $dst_x =0; } else { $src_x =0; $dst_x = (int) ($dst_width - $this->src_width)/2; } if( ($dst_height -$this->src_height) < 0) { $src_y = (int) ($this->src_height - $dst_height)/2; $dst_y = 0; } else { $src_y = 0; $dst_y = (int) ($dst_height - $this->src_height)/2; } imagecopy($this->dImage, $this->sImage,$dst_x,$dst_y,$src_x,$src_y,$this->src_width,$this->src_height); } break; case 3: // keep all image size and create need size if($ratio_w > 1 && $ratio_h > 1) { $dst_x = (int)(abs($dst_width - $this->src_width )/2) ; $dst_y = (int)(abs($dst_height- $this->src_height)/2) ; imagecopy($this->dImage, $this->sImage, $dst_x,$dst_y,0,0,$this->src_width,$this->src_height); } else { $ratio = $ratio_w > $ratio_h ? $ratio_h : $ratio_w; $tmp_w = (int)($this->src_width * $ratio); $tmp_h = (int)($this->src_height * $ratio); $tmp_img=imagecreatetruecolor($tmp_w ,$tmp_h); imagecopyresampled($tmp_img,$this->sImage,0,0,0,0,$tmp_w,$tmp_h,$this->src_width,$this->src_height); $dst_x = (int)(abs($tmp_w -$dst_width )/2) ; $dst_y = (int)(abs($tmp_h -$dst_height)/2) ; imagecopy($this->dImage, $tmp_img, $dst_x,$dst_y,0,0,$tmp_w,$tmp_h); imagedestroy($tmp_img); } break; case 4: // keep all image but create actually size if($ratio_w > 1 && $ratio_h > 1) { $this->dImage = imagecreatetruecolor($this->src_width,$this->src_height); imagecopy($this->dImage, $this->sImage,0,0,0,0,$this->src_width,$this->src_height); } else { $ratio = $ratio_w > $ratio_h ? $ratio_h : $ratio_w; $tmp_w = (int)($this->src_width * $ratio); $tmp_h = (int)($this->src_height * $ratio); $this->dImage = imagecreatetruecolor($tmp_w ,$tmp_h); imagecopyresampled($this->dImage,$this->sImage,0,0,0,0,$tmp_w,$tmp_h,$this->src_width,$this->src_height); } break; } } // end Crop}?>

PS:這里再為大家推薦幾款比較實用的圖片處理工具供大家參考使用:

在線圖片轉換BASE64工具:http://tools.jb51.net/transcoding/img2base64

ICO圖標在線生成工具:http://tools.jb51.net/aideddesign/ico_img

在線Email郵箱圖標制作工具:http://tools.jb51.net/email/emaillogo

在線圖片格式轉換(jpg/bmp/gif/png)工具:http://tools.jb51.net/aideddesign/picext

更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結》、《php面向對象程序設計入門教程》、《PHP網絡編程技巧總結》、《PHP數組(Array)操作技巧大全》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》

希望本文所述對大家PHP程序設計有所幫助。

總結

以上是生活随笔為你收集整理的php dimage加上域名,PHP全功能无变形图片裁剪操作类与用法示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产熟女一区二区三区四区 | 欧美xxxx黑人又粗又长密月 | 日本在线视频二区 | 蜜桃视频在线网站 | 国产ts人妖系列高潮 | 嫩草影院在线免费观看 | hd性videos意大利精品 | 一卡二卡三卡四卡在线 | 亚洲欧美色图片 | 韩国中文字幕在线观看 | 一区二区高清在线 | 日本精品视频在线 | 九九精品网| 国产极品美女高潮无套在线观看 | 精品国产乱码久久久久夜深人妻 | 激情戏网站| 欧美色欧美色 | 99re99| 美妇湿透娇羞紧窄迎合 | 色丁香婷婷综合久久 | 日韩成人区 | 极品久久久久久 | 色戒电影未测减除版 | 人妻无码一区二区三区久久 | 欧美成人视屏 | a级片免费播放 | 欧美日日日 | 成人片黄网站色大片免费毛片 | 国产有码视频 | 欧美综合自拍亚洲综合图片区 | 亚洲视频在线观看一区二区 | 国产精品美女一区二区 | 一区二区在线观看av | 久久三级网站 | 99久久影院 | 69视频一区二区 | 911精品| 性爽爽| 日韩福利网站 | 手机在线视频一区 | 欧美日韩中字 | 久久久精品日本 | 亚洲国产精品va在线 | 奇米影视一区二区 | 伊人久久精品一区二区三区 | 无遮挡aaaaa大片免费看 | 日韩一区二区免费在线观看 | www.成年人 | 无码内射中文字幕岛国片 | 在线看黄色网 | 麻豆伊甸园 | www.国产成人 | 爱爱短视频 | 欧美在线一区二区三区 | h片免费网站 | 国产亚洲一区二区不卡 | 精品无码久久久久久久久 | 中文字幕11页中文字幕11页 | 在线观看亚洲精品视频 | 麻豆久久久久久久 | 黄色小视频网 | 日韩一区二区中文字幕 | 老司机深夜福利在线观看 | 日本女优一区 | 黄a大片| 国产影视一区二区三区 | 国产精品国产三级国产在线观看 | 欧美在线播放一区 | 国产青青| 欧美又大粗又爽又黄大片视频 | 久久99久久久 | 日韩精品一区二区三 | 亚洲国产综合一区 | 女人性高潮视频 | 毛片基地免费观看 | 豆花视频成人 | 欧美大尺度视频 | 红桃视频黄色 | 影音先锋成人资源网站 | 在线成人播放 | 毛片大全免费看 | 精品国产成人亚洲午夜福利 | 国产欧美日 | 日本一二三区在线视频 | 超碰在线99 | 91精品国产综合久久香蕉922 | 国产精品日韩欧美大师 | 色婷婷一区二区三区四区 | 国产ts网站 | 无码国产精品一区二区免费16 | 精品麻豆一区二区 | 一级高清视频 | 天堂资源 | 国产精品99re | 午夜偷拍福利视频 | 精品久久无码中文字幕 | 亚洲妇熟xx妇色黄蜜桃 | a∨色狠狠一区二区三区 | 在线观看国产精品入口男同 |