|
imagecopyresized (PHP 3, PHP 4, PHP 5) imagecopyresized -- 複製部分圖像並調整大小 說明bool imagecopyresized ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )
imagecopyresized()
將一幅圖像中的一塊正方形區功能變數複製到另一個圖像中。dst_image
和 src_image
分別是目的圖像和源圖像的標識符。若果源和目的的寬度和高度不同,則會進行相應的圖像收縮和拉伸。坐標指的是左上角。本函數可用來在同一幅圖內定複製(若果
dst_image 和 src_image
相同的話)區功能變數,但若果區功能變數交迭的話則結果不可預知。
注:
因為調色板圖像限制(255+1 種彩色)有個問題。重取樣或過濾圖像通常需要多於 255
種彩色,計算新的被重取樣的像素及其彩色時採用了一種近似值。對調色板圖像嘗試配置一個新彩色時,若果失敗我們選取了計算結果最接近(理論上)的彩色。這並不總是視覺上最接近的彩色。這可能會產生怪異的結果,例如空白(或是視覺上是空白)的圖像。要略過這個問題,請使用真彩色圖像作為目的圖像,例如用
imagecreatetruecolor() 建立的。
範例
例子 1. 調整圖像大小
本例將以原來的一半大小顯示圖像。
<?php // File and new size $filename = 'test.jpg'; $percent = 0.5;
// Content type header('Content-type: image/jpeg');
// Get new sizes list($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent;
// Load $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromjpeg($filename);
// Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output imagejpeg($thumb); ?>
|
圖像將以一半大小輸出,不過可以用
imagecopyresampled() 得到更好的質量。
|
| |