url
https://three.api.skinrun.me/web/index/imgs?w=500&h=500&url={$goodsInfo['thumbs']}
调用截取函数
public function imgs(){
$url = $_GET['url'];
$width = $_GET['w'];
$height = $_GET['h'];
imageResizer($url,$width,$height);
}
function imageResizer($url, $width, $height)
{
$imgType = pathinfo($url, PATHINFO_EXTENSION);
if ($imgType == 'png')
{
header('Content-Type: image/png');
} else
{
header('Content-Type: image/jpeg');
}
list($width_orig, $height_orig) = getimagesize($url);
$ratio_orig = $width_orig / $height_orig;
if ($width / $height > $ratio_orig)
{
$width = $height * $ratio_orig;
} else
{
$height = $width / $ratio_orig;
}
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($url);
if (!$image)
{
$image = imagecreatefrompng($url);
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
if ($imgType == 'png')
{
imagepng($image_p);
} else
{
imagejpeg($image_p);
}
}
注意:开启GD库
网友评论