我在谷歌上找到了这个功能,但它不起作用。我使用 818x800 图像进行了测试,该函数将返回相同的大小。怎么了 ?
function imageResize($width, $height, $target) {
//takes the larger size of the width and height and applies the formula accordingly...this is so this script will work dynamically with any size image
if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}
//gets the new value and applies the percentage, then rounds the value
$width = round($width * $percentage);
$height = round($height * $percentage);
//returns the new sizes in html image tag format...this is so you can plug this function inside an image tag and just get the
return "width=\"$width\" height=\"$height\"";
}
$mysock = getimagesize("http://www.pirate-punk.com/pochette.php?i=ZGwvcHAvNjI1MC84NiBDcmV3IC0gMjAwMCAtIEJhZCBCYWQgUmVnZ2FlLnppcCM4IDYgQ3JldyAtIEJhZCBCYWQgUmVnZ2FlLWZyb250ICBbd3d3LlBpcmF0ZS1QdW5rLm5ldF0uanBnCg==");
echo "<img src=\"$pochetteimg\" ";
imageResize($mysock[0], $mysock[1], 300);
echo ">";
我正在尝试将图像大小调整为 300px 宽度,同时保持比例