1

我有一个用于缩放成员个人资料图像的脚本,我想知道在不过度扭曲图像原始比例的情况下,对个人资料图片执行缩放的正确方法是什么。上传时保持图像纵横比的逻辑是什么?目前我使用这段代码来执行我的缩放

//SCALING IMAGES 
    $newwidth = 301;
    $newheight = ceil(($height/$width)*$newwidth);
    $tmp = imagecreatetruecolor($newwidth,$newheight);


    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

感谢您的时间。

4

1 回答 1

0

您应该设置示例来设置图像重采样大小:

class imagemanipulate
{
public function set_size($max_x = 100,$max_y = 100)
{

    // Resize
    if($this->x_input > $max_x || $this->y_input > $max_y)
    {

    $a= $max_x / $max_y;
    $b= $this->x_input / $this->y_input;

    if ($a<$b)
    {

        $this->x_output = $max_x;
        $this->y_output = ($max_x / $this->x_input) * $this->y_input;

    }
    else
    {

        $this->y_output = $max_y;
        $this->x_output = ($max_y / $this->y_input) * $this->x_input;

    }
    // Ready

    $this->resize = TRUE;

    }

    // Don't resize       
    else { $this->resize = FALSE; }

}
 }


 $inst = new imagemanipulate;
 $inst->set_size('301', '301');

 $tmp = imagecreatetruecolor($inst->x_output,$inst->y_output);


 imagecopyresampled($tmp,$src,0,0,0,0,$inst->x_output,$inst->y_output,$width,$height);

?>
于 2013-02-24T23:29:34.377 回答