Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何处理意外的宽度和高度_Php_Image Resizing - Fatal编程技术网

Php 如何处理意外的宽度和高度

Php 如何处理意外的宽度和高度,php,image-resizing,Php,Image Resizing,我目前正在使用以下代码将所有大于800 x600的图像重新调整为所需大小 if (($width>800) and ($height>600)) { WideImage::load($img_path.$name)->resize(800, 600)->saveToFile($img_path.$name); } 但是,例如,如果图像的宽度为1024,高度为559,则这将不起作用 我可以使用or,但我不确定如何调整这些图像的大小。我一直发现调整图像大小最可靠的方法是使

我目前正在使用以下代码将所有大于800 x600的图像重新调整为所需大小

if (($width>800) and ($height>600))
{
WideImage::load($img_path.$name)->resize(800, 600)->saveToFile($img_path.$name);

}
但是,例如,如果图像的宽度为1024,高度为559,则这将不起作用

我可以使用or,但我不确定如何调整这些图像的大小。

我一直发现调整图像大小最可靠的方法是使用高度与宽度的比率

psuedocode代码如下所示:

$widthRatio=$originalImageHeight/$originalImageWidth;
$newImage=resize(800, 800*$widthRatio);
然后将其调整为800,同时保持原始比率


此外,您可能需要设置或至少检查比率,这样您就不会上传1000 x 20000的图像,如果您将其调整为800 x 16000,它仍然会弄乱您的站点,因为php是一个预处理器,它不会工作,因为当您运行scripCheck时,图像不会加载,而scripCheck是较大的维度(宽度或高度)然后只调整特定维度的大小,这样做时保留纵横比。您是否尝试过使用css
max width
属性?