我有以下功能,运行25次思考,并延迟网站的加载时间10秒或更多。代码基本上做的是在图像宽度缩小或高达310px时计算高度。关于如何改进我的代码或提出其他选择的任何建议?也许jQuery可能会更好呢?优化缩放图像的方式
function img_height($image){
$inputwidth = 310;
list($width,$height) = getimagesize($image);
if($width !== $inputwidth){
$outputheight = ($inputwidth * $height)/ $width;
}elseif($width == $inputwidth){
$outputheight = $height;
}
return 'style="height:'.$outputheight.'px;" ';
}
你不需要'elseif'只需使用'else'。 – andlrc 2013-05-10 08:20:58
服务器上还是其他地方的图像? – Wurstbro 2013-05-10 08:22:06
@Wurstbro他们正在从imgur拉出。 – Harry 2013-05-10 08:23:56