0

我在谷歌上找到了这个功能,但它不起作用。我使用 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 宽度,同时保持比例

4

3 回答 3

0
<?php
function imageResize($width, $height, $target) {
if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); }
$width = round($width * $percentage);
$height = round($height * $percentage);
return "width=\"$width\" height=\"$height\"";
}

$mysock = getimagesize("pochette.jpg");
$size = imageResize($mysock[0], $mysock[1], 300);
echo "<img src=\"pochette.jpg\" ".$size." />";
?>

像这样试试。

于 2013-07-23T08:49:00.807 回答
0

试试这样:

$mysock = getimagesize("YourUrl");
echo "<img src='" . $pochetteimg . "' " . imageResize($mysock[0], $mysock[1], 300) . "/>";
于 2013-07-23T08:50:30.887 回答
0

imageresize功能实际上并未调整图像大小。它只是返回保持纵横比的图像的宽度和高度。这是你想要达到的目标吗?

于 2013-07-23T08:52:40.507 回答