導航:首頁 > 編程語言 > php裁剪並縮放圖片

php裁剪並縮放圖片

發布時間:2025-06-30 19:57:59

Ⅰ easyphpthumbnail,phpthumb哪 個更好

EasyPHPThumbnail類可以處理圖像和PHP生成縮略圖支持GIF、JPG和PNG。這個類是免費的,基於100%的PHP,可用於PHP4(4.3.11以上)和PHP5,易於使用,並提供了超過60的功能操作:
提供的功能包括:調整大小,裁剪,旋轉,翻轉,另存為,陰影,水印,文字,邊框,銳化,模糊,水波紋,反射鏡,透視,動畫,置換貼圖和更多!
使用簡介
1、基本使用
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Createthumb('gfx/image.jpg');
?>
2、動態顯示指定大小圖片
<?php
include_once('inc/easyphpthumbnail.class.php');
// Your full path to the images
$dir = str_replace(chr(92),chr(47),getcwd()) . '/gfx/';
// Create the thumbnail
$thumb = new easyphpthumbnail;
$thumb -> Thumbsize = 300;
$thumb -> Createthumb($dir . 'img.jpg');
?>
3、生成靜態多張本地圖片
<?php
include_once('inc/easyphpthumbnail.class.php');
// Your full path to the images
$dir = str_replace(chr(92),chr(47),getcwd()) . '/gfx/';
$dir_thumbs = str_replace(chr(92),chr(47),getcwd()) . '/thumbs/';
if(!is_dir($dir_thumbs)) mkdir($dir_thumbs,0777);
// Create the thumbnail
$thumb = new easyphpthumbnail;
$thumb -> Thumbsize = 600;
$thumb -> Copyrighttext = 'SCUTEPHP.COM';
$thumb -> Copyrightposition = '50% 90%';
$thumb -> Copyrightfonttype = $dir . 'handwriting.ttf';
$thumb -> Copyrightfontsize = 30;
$thumb -> Copyrighttextcolor = '#FFFFFF';
$thumb -> Chmodlevel = '0755';
$thumb -> Thumblocation = $dir_thumbs;
$thumb -> Thumbsaveas = 'jpg';
$thumb -> Thumbprefix = '120px_thumb_';
$thumb -> Createthumb(array($dir . '69.jpg', $dir . '70.jpg'), 'file');
?>
4、圖片大小百分比調整及圖片旋轉
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Thumbsize = 50;
$thumb -> Rotate = 90;//指定度數旋轉
//$thumb -> Fliphorizontal = true; //水平軸旋轉
//$thumb -> Flipvertical = true; //垂直軸旋轉
$thumb -> Percentage = true;
$thumb -> Createthumb('gfx/image.jpg');
?>
Thumbsize默認是px像素單位,然而要用百分比的話可以設置Percentage屬性為ture,Rotate屬性設置順時針旋轉度數。
5、給縮略圖增加背景陰影
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Backgroundcolor = '#D0DEEE';
$thumb -> Shadow = true;
$thumb -> Createthumb('gfx/image.jpg');
?>
6、給縮略圖增加圓角效果
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Backgroundcolor = '#D0DEEE';
$thumb -> Clipcorner = array(2,15,0,0,1,1,0);
$thumb -> Createthumb('gfx/image.jpg');
?>
Clipcorner屬性的7個參數含義
[0]: 0=關閉 1=直角 2=圓角
[1]: 裁剪比例
[2]: 隨機 - 0=關閉 1=開啟
[3]: 左上 - 0=關閉 1=開啟
[4]: 左下 - 0=關閉 1=開啟
[5]: 右上 - 0=關閉 1=開啟
[6]: 右下 - 0=關閉 1=開啟
7、給縮略圖增加透明效果
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Backgroundcolor = '#0000FF';
$thumb -> Clipcorner = array(2,15,0,1,1,1,1);
$thumb -> Maketransparent = array(1,1,'#0000FF',30);
$thumb -> Createthumb('gfx/image.jpg');
?>
8、給縮略圖增加框架效果
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Framewidth = 10;
$thumb -> Framecolor = '#FFFFFF';
$thumb -> Backgroundcolor = '#D0DEEE';
$thumb -> Shadow = true;
$thumb -> Createthumb('gfx/image.jpg');
?>
9、給縮略圖增加經典相框效果
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Framewidth = 10;
$thumb -> Framecolor = '#FFFFFF';
$thumb -> Backgroundcolor = '#D0DEEE';
$thumb -> Shadow = true;
$thumb -> Binder = true;
$thumb -> Binderspacing = 8;
$thumb -> Clipcorner = array(2,15,0,1,1,1,0);
$thumb -> Createthumb('gfx/image.jpg');
?>
10、給縮略圖增加水印效果
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Thumbsize = 300;
$thumb -> Framewidth = 10;
$thumb -> Framecolor = '#00000';
$thumb -> Backgroundcolor = '#000000';
$thumb -> Clipcorner = array(2,15,0,1,1,1,1);
$thumb -> Watermarkpng = 'watermark.png';
$thumb -> Watermarkposition = '50% 50%';
$thumb -> Watermarktransparency = 70;
$thumb -> Createthumb('gfx/image.jpg');
?>
11、給縮略圖增加短文本及相框
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Thumbsize = 300;
$thumb -> Framewidth = 10;
$thumb -> Framecolor = '#00000';
$thumb -> Borderpng = 'border.png';
$thumb -> Copyrighttext = 'MYWEBMYMAIL.COM';
$thumb -> Copyrightposition = '50% 80%';
$thumb -> Copyrightfonttype = 'handwriting.ttf';
$thumb -> Copyrightfontsize = 30;
$thumb -> Copyrighttextcolor = '#FFFFFF';
$thumb -> Createthumb('gfx/image.jpg');
?>
12、縮略圖按指定形狀裁剪
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Thumbsize = 300;
$thumb -> Borderpng = 'cloud.png';
$thumb -> Createthumb('gfx/image.jpg');
?>
13、指定區域裁剪圖片
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Thumbsize = 300;
$thumb -> Cropimage = array(2,0,20,20,35,35);
$thumb -> Createthumb('gfx/image.jpg');
?>
Cropimage屬性六個參數說明
[0]: 0=disable 1=enable free crop 2=enable center crop
[1]: 0=percentage 1=pixels
[2]: Crop left
[3]: Crop right
[4]: Crop top
[5]: Crop bottom
14、裁剪出舊照片效果
<?php
include_once('inc/easyphpthumbnail.class.php');
$thumb = new easyphpthumbnail;
$thumb -> Thumbsize = 300;
$thumb -> Shadow = true;
$thumb -> Backgroundcolor = '#D0DEEE';
$thumb -> Cropimage = array(2,0,20,20,35,35);
$thumb -> Ageimage = array(1,10,80);
$thumb -> Createthumb('gfx/image.jpg');
?>
15、屬性或方法詳解
A
$thumb -> Addtext = array()// 對原始圖像添加文字
數組有六個參數
[0]: 0=disable 1=enable
[1]: The text to add
[2]: The position of the text '50% 50%' is the center
[3]: Path to the TTF font (standard systemfont will be used)
[4]: The fontsize to use
[5]: The right text color in web format '#000000'
$thumb -> Ageimage = (array) // 應用灰度 array(1,0,0) 或者舊照片效果 array(1,10,80)
數組有六個參數
[0]: Boolean 0=disable 1=enable
[1]: Add noise 0-100, 0=disable
[2]: Sephia depth 0-100, 0=disable (greyscale)
$thumb -> Applyfilter = (boolean)// 應用用戶自定義3x3過濾器
B
$thumb -> Backgroundcolor = (string)// Web格式的背景 '#FFFFFF'
$thumb -> Binder = (boolean) // 在縮略圖左邊畫一粘合劑
$thumb -> Binderspacing = (int) // 以像素為單位的空間
$thumb -> Blur = (boolean) // 模糊過濾器
$thumb -> Borderpng = (string) // 邊框PNG圖片路徑
$thumb -> Brightness = (array) // 改變圖片亮度
數組有兩個參數
[0]: Boolean 0=disable 1=enable
[1]: Brightness -100 to 100
C
$thumb -> Chmodlevel = (string) // 設置保存圖片的許可權 '0755'
$thumb -> Clipcorner = (array) // 設置圓角 array(2,15,0,1,1,1,0)
數組有七個參數
[0]: 0=disable 1=straight 2=rounded
[1]: Percentage of clipping
[2]: Clip randomly Boolean 0=disable 1=enable
[3]: Clip top left Boolean 0=disable 1=enable
[4]: Clip bottom left Boolean 0=disable 1=enable
[5]: Clip top right Boolean 0=disable 1=enable
[6]: Clip bottom right Boolean 0=disable 1=enable
$thumb -> Colorreplace = (array)// 顏色替換 array(1,'#FFFFFF','#FF6600',60)
數組有四個參數
[0]: Boolean 0=disable 1=enable
[1]: Color to replace in web format: '#00FF00'
[2]: Replacement color in web format: '#FF0000'
[3]: RGB tolerance 0 - 100
$thumb -> Colorize = (array) // 合並圖像中的顏色 array(1,0,0,125,0)
數組有五個參數
[0]: Boolean 0=disable 1=enable
[1]: Red component 0 - 255
[2]: Green component 0 - 255
[3]: Blue component 0 - 255
[4]: Opacity level 0 - 127
$thumb -> Contrast = (array)// 改變圖像的對比度 array(1,30)
數組有2個參數
[0]: Boolean 0=disable 1=enable
[1]: Contrast -100 to 100
$thumb -> Copyrighttext = (string) // 增加版權文本
$thumb -> Copyrightposition = (string) // 版權文本位置 '50% 50%' is the center
$thumb -> Copyrightfonttype = (string)// TTF文字字體路徑 (standard systemfont will be used)
$thumb -> Copyrightfontsize = (int)// 字體大小
$thumb -> Copyrighttextcolor = (string) // 文字Web格式顏色值 '#000000'
$thumb -> Createthumb('imagepath'[,'output']) // 創建或者輸出縮略圖
函數有兩個參數
[string/array]: 原圖片完整路徑字元串或數組
[string]: Output to the 'screen' (standard) or 'file' (option)
$thumb -> Createbase64('imagepath')// 以base64數據輸出圖片
函數有一個參數
[string]: Filename for image to convert
$thumb -> Createcanvas(i,i,i,s,b)// 創建一個畫布圖像 - use with Createthumb()
函數有五個參數
[int]: Canvas width in pixels
[int]: Canvas height in pixels
[int]: Imagetype PHP: IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG
[string]: Fill color
[boolean]: Transparent (boolean)
$thumb -> Create_apng(array, string, int)// 創建APNG縮略圖
函數有三個參數
[array]: Array with filenames of PNG images (frames)
[string]: Filename for APNG: 'animation.png'
[int]: Delay between frames in milliseconds
$thumb -> Cropimage = (array)// 裁剪 array(0,0,20,20,20,20)
數組有六個參數
[0]: 0=disable 1=free crop 2=center crop 3=square crop
[1]: 0=percentage 1=pixels
[2]: Crop left
[3]: Crop right
[4]: Crop top
[5]: Crop bottom
$thumb -> Croprotate = (boolean)// 裁剪圖片到同樣大小的畫布並旋轉
D
$thumb -> Displacementmap = (array) // 變形
數組有7個參數: array(1,'gfx/displacementmap.jpg',0,0,0,50,50)
[0]: 0=disable 1=enable
[1]: Path to displacement image (grey #808080 is neutral)
[2]: 0=resize the map to fit the image 1=keep original map size
[3]: X coordinate for map position in px
[4]: Y coordinate for map position in px
[5]: X displacement scale in px
[6]: Y displacement scale in px
$thumb -> Displacementmapthumb = (array) // 縮略圖變形
數組有七個參數: array(1,'gfx/displacementmap.jpg',0,0,0,50,50)
[0]: 0=disable 1=enable
[1]: Path to displacement image (grey #808080 is neutral)
[2]: 0=resize the map to fit the image 1=keep original map size
[3]: X coordinate for map position in px
[4]: Y coordinate for map position in px
[5]: X displacement scale in px
[6]: Y displacement scale in px
$thumb -> Divisor = (int)// The divisor for the 3x3 filter
E
$thumb -> Edge = (boolean)// 邊緣過濾器
$thumb -> Emboss = (boolean) // 浮雕過濾器
F
$thumb -> Fliphorizontal = (boolean)// 在水平軸翻轉圖像
$thumb -> Flipvertical = (boolean) // 在垂直軸翻轉圖像
$thumb -> Filter = (array)// 3x3矩陣 array(-1,-1,-1,-1,8,-1,-1,-1,-1)
數組有九個參數
[0]: a1,1
[1]: a1,2
[2]: a1,3
[3]: a2,1
[4]: a2,2
[5]: a2,3
[6]: a3,1
[7]: a3,2
[8]: a3,3
$thumb -> Framewidth = (int)// 添加縮略圖框架(像素)
$thumb -> Framecolor = (string) // 框架顏色 '#FFFFFF'

Ⅱ 哪位幫我解決一下wordpress的timthumb.php

讓TimThumb工作是相當直接的。直接下載TimThumb代碼在你的網站上,在timthumb.php同一個目錄下添加一個叫「cache」的文件夾,許可權設置為775。其實就已經完成了,接下來的就是是使用了。

注意:緩存目錄應與775年唯一的文件/目錄許可權。 腳本,腳本文件夾,和任何其他文件夾應該有您的伺服器的默認值。

基本參數

下面的參數是主要的使用。 這些您可以調整幾乎任何事情。

//常用參數演示
timthumb.php?src=my_image.jpg&h=260&w=260&zc=1&q=95

src —— 這是唯一必須的參數。其他的都是可選的。 如果你只指定源屬性那麼形象將裁剪/大小默認維度(100 x 100)

w/h —— 寬度和高度。可選,也幾乎必不可少的,很少人想要默認大小。 寬度和高度可以是任何值,TimThumb將根據需要放大或縮小。

zc —— 1為裁剪,0為縮放

q —— 質量。 這將指定圖像的壓縮級別被裁剪/調整大小。

以上內容參考資料:http://zhan.leiue.com/timthumb-use.html(版權歸原作者和網站所有)

Ⅲ ThinkPHP3.2.3 上傳圖片到ftp,同時生成縮略圖。

ThinkPHP上傳文件類:

$upload = new ThinkUpload($config);// 實例化上傳類

使用這個。

如要處理圖片大小。需要另外調用圖像處理:

裁剪圖片

$image=newThinkImage();
$image->open('./1.jpg');
//將圖片裁剪為400x400並保存為corp.jpg
$image->crop(400,400)->save('./crop.jpg');
居中裁剪
$image=newThinkImage();
$image->open('./1.jpg');
//生成一個居中裁剪為150*150的縮略圖並保存為thumb.jpg
$image->thumb(150,150,ThinkImage::IMAGE_THUMB_CENTER)->save('./thumb.jpg');
閱讀全文

與php裁剪並縮放圖片相關的資料

熱點內容
linux編譯器軟體包 瀏覽:51
和平精英ak解壓視頻 瀏覽:762
lg安卓手機如何下載微信 瀏覽:32
php清理所有變數 瀏覽:725
beanshell編程 瀏覽:920
安卓車機怎麼開啟駕車模式 瀏覽:97
程序員三個字作詩 瀏覽:765
安卓怎麼錄入羊城通 瀏覽:151
領克手機app不更新怎麼處理 瀏覽:938
安陽數控編程怎麼學 瀏覽:973
數據加密常用演算法 瀏覽:922
很多程序員進考場時候的照片 瀏覽:10
php數組key相同 瀏覽:368
win7編譯linux 瀏覽:843
程序員食堂阿姨 瀏覽:927
耳機能加密嗎 瀏覽:884
伺服器lol手游崩了怎麼辦 瀏覽:169
飛盧app怎麼看id 瀏覽:518
騰訊雲輕量伺服器藍屏 瀏覽:613
php網站後台開發 瀏覽:477