PHP调整图像大小以适合特定区域

PHP调整图像大小以适合特定区域,php,image,resize,Php,Image,Resize,我有一个存储在变量$image中的图像文件,我想调整此图像的大小,使其适合380px×380px的区域(这意味着图像的最高一侧必须是380px,另一侧必须小于380px)。 有人建议怎么做吗 谢谢这是我用来保持800x600以下的 $orig_image = imagecreatefromjpeg($file['tmp_name']); list($width,$height) = getimagesize($file['tmp_name']); if(max($width,$height) &

我有一个存储在变量
$image
中的图像文件,我想调整此图像的大小,使其适合380px×380px的区域(这意味着图像的最高一侧必须是380px,另一侧必须小于380px)。 有人建议怎么做吗


谢谢

这是我用来保持800x600以下的

$orig_image = imagecreatefromjpeg($file['tmp_name']);
list($width,$height) = getimagesize($file['tmp_name']);
if(max($width,$height) > 800){
  $scale = 800/max($width,$height);
  $new_width = floor($width*$scale);
  $new_height = floor($height*$scale);
  $save_image = imagecreatetruecolor($new_width,$new_height);
  imagecopyresampled($save_image,$orig_image,0,0,0,0,$new_width,$new_height,$width,$height);
  imagejpeg($save_image,self::$FILE_DIRECTORY."$year_month/$fileId.jpg");
  $orig_image = $save_image;
  $width = $new_width;
  $height = $new_height;
}

希望你能从中推断出一个解决方案。。也不是说我的$file变量来自$\u文件数组中上载的文件。

你是想永久更改图像,还是只是以特定的大小显示它?基本上是@BrianWarshaw的副本永久更改它。@slugonamission谢谢,我会查看它。也不用担心最后三个变量(我还创建缩略图,这就是它们的用途)非常方便。非常适合我使用。