標籤:10個 html zed style 顏色 idt sina res 實現
http://blog.sina.com.cn/s/blog_68b56adb0100vq1a.html
相簿程式、圖片縮圖的產生是必不可少的一個功能,用PHP的GD函數為圖片產生縮圖是很簡單的,核心就一個
imagecopyresampled函數。主要麻煩的是要考慮圖片的各種長、寬、縮放比等等東西。
如果對縮圖的品質要求不高可以使用imagecopyresized()函數,imagecopyresize()所產生的映像比較粗糙,但是速度較快;imagecopyresampled()函數是GD 2.x後新增加的函數,字面上的意思是會對圖片進行重新採樣(resampling),GD是採用插值演算法產生更平滑的映像,但是速度相對imagecopyresize()函數來說要慢一些。
imagecopyresample() 共有10個參數,前面兩個是目標檔案和源檔案,後面4個分別是dst和src的width,height,中間的 src_x,src_y,dst_x,dst_y看得比較暈。。例子裡面都是設定為0,後來試了下,發現把這4個參數寫成 dst_start_x, dst_start_y, src_start_x, src_start_y的話就很好理解了。舉個例子說吧。假如要在縮圖上下各留10 pixel的空白,那就可以用imagecopyresampled($dst, $src, dst_start_x, dst_start_y + 10, src_start_x, src_start_y, dst_width, dst_height – 20, src_width, src_height)來實現。
用imagecreatetruecolor(int x,int y)建立的是一幅大小為 x和 y的黑色映像(預設為黑色),如想改變背景顏色則需要用填充顏色函數imagefill($img,0,0,$color);
imagecreate 建立一個空白映像資源,用imagecolorAllocate()添加背景色
<?php
$img =imagecreatetruecolor(100,100);
//建立真彩映像資源
$color =imagecolorAllocate($img,200,200,200); //分配一個灰色
imagefill($img,0,0,$color); // 從左上方開始填充灰色
header(‘content-type:image/jpeg‘); //jpg格式
imagejpeg($img); //顯示灰色的方塊
?>
<?php
$img = imagecreate(100,100);
$color = imagecolorallocate($img,200,200,200);
header(‘content-type:image/jpeg‘);
//jpg格式
imagejpeg($img); //顯示灰色的方塊
?>
PHP映像函數