2014-02-23 34 views
-1

我正在使用PHP代碼來製作縮略圖並使其適合它們。我附上了我想要的照片。我很喜歡的劇本是拉伸形象。這些腳本不適合圖像寬度明智和高度明智。用於自動調整圖像的PHP代碼

任何人都可以請幫我分揀這個問題。 enter image description here

回答

0

我不知道什麼是你的代碼錯誤,因爲你還沒有公佈,但這裏是我用來創建縮略圖

function make_thumb($src, $dest, $desired_width) { 

    /* read the source image */ 
    $source_image = imagecreatefromjpeg($src); 
    $width = imagesx($source_image); 
    $height = imagesy($source_image); 

    /* find the "desired height" of this thumbnail, relative to the desired width */ 
    $desired_height = floor($height * ($desired_width/$width)); 

    /* create a new, "virtual" image */ 
    $virtual_image = imagecreatetruecolor($desired_width, $desired_height); 

    /* copy source image at a resized size */ 
    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height); 

    /* create the physical thumbnail image to its destination */ 
    imagejpeg($virtual_image, $dest); 
} 

$ SRC一個方便的功能: URL到您的圖像
$ DES:在您想要的縮略圖是
$寬度:您的縮略圖的寬度

This code is from here