試試這個....這將幫助..
if(file_exists('test.jpg'))
unlink('test.jpg');
$dest='test.jpg';
$image='fg.jpg';
$list=getimagesize($image);
$width=$list[0];
$height=$list[1];
$newwidth=65;
$newheight=95;
$int_x=10;
$int_y=0;
define('DESIRED_IMAGE_WIDTH', 65);
define('DESIRED_IMAGE_HEIGHT', 95);
$source_gdim = imagecreatefromjpeg($image);
$source_aspect_ratio = $width/$height;
$desired_aspect_ratio = DESIRED_IMAGE_WIDTH/DESIRED_IMAGE_HEIGHT;
// For Wide Image
if ($source_aspect_ratio > $desired_aspect_ratio)
{
$temp_height = DESIRED_IMAGE_HEIGHT;
$temp_width = (int) (DESIRED_IMAGE_HEIGHT * $source_aspect_ratio);
}
// For Tall Image
else
{
$temp_width = DESIRED_IMAGE_WIDTH;
$temp_height = (int) (DESIRED_IMAGE_WIDTH/$source_aspect_ratio);
}
$temp_gdim = imagecreatetruecolor($temp_width, $temp_height);
imagecopyresampled($temp_gdim,$source_gdim,0, 0,0, 0,$temp_width, $temp_height,$width, $height);
$x0 = ($temp_width - DESIRED_IMAGE_WIDTH)/2;
$y0 = ($temp_height - DESIRED_IMAGE_HEIGHT)/2;
$desired_gdim = imagecreatetruecolor(DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT);
imagecopy($desired_gdim,$temp_gdim,0, 0,$x0, $y0,DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT);
imagejpeg($desired_gdim,'test.jpg',100);
您好,感謝這一點。它不是codeigniter特定的,但我想我可以使用一些代碼來將我的圖像調整爲特定的尺寸,然後相應地裁剪。 :) 多謝,夥計。 – 2012-03-19 11:24:13