调整图像后如何编写图像

时间:2016-04-28 10:02:12

标签: php

我正在尝试使用我从PHP官方网站获得的功能调整照片大小。这是一个在不失去比例的情况下调整照片大小的功能。

public function ImageResize($filename, $max_width,$max_height){

    list($orig_width,$orig_height) = getimagesize($filename);

    $width = $orig_width;
    $height = $orig_height;

    #c'est la photo est grande.
    if($height > $max_height){
        $width = ($max_height/$height) * $width;
        $height = $max_height;
    }

    #c'est la photo est larage
    if($width > $max_width){
        $height = ($max_width/$width) * $height;
        $width = $max_width;
    }

    $image_p = imagecreatetruecolor($width,$height);

    $image = imagecreatefromjpeg($filename);

    imagecopyresampled($image_p, $image, 0, 0, 0, 0,
        $width, $height, $orig_width, $orig_height);

    return $image_p;

}

这个函数应该给我发一张照片,问题是:缩小的图像是自动写入磁盘还是我需要做更多的处理才能在旧图片和新图片之间进行更改。

1 个答案:

答案 0 :(得分:2)

图像只能在变量$ image_p中使用,直到您保存它为止。像这样:

imagejpeg($image_p, 'your_image_in_disk.jpg');
相关问题