我使用的URL链接到调整大小的图像,如:调整图像尺寸PHP
image.php?name=butterfly&size=1100x1100
例如:
<img src="image.php?name=butterfly&size=1100x1100">
我正在使用的代码是:
<?php
if(isset($_GET['name'])){ //name
$image['name'] = $_GET['name'];
} else {
$image['name'] = null;
}
if(isset($_GET['size'])){ //dimensions
$image['size'] = $_GET['size'];
$size = explode('x', $image['size']);
$image['width'] = $size[0];
$image['height'] = $size[1];
} else {
$image['size'] = null;
}
if(isset($_GET['text'])){ //text
$image['text'] = $_GET['text'];
} else {
$image['text'] = null;
}
// File and new size
$filename = 'images/'.$image["name"].'.jpeg';
// Content type
header('Content-Type: image/jpeg');
// Output
imagecreatefromjpeg($filename);
// Set a maximum height and width
$width = $image['width'];
$height = $image['height'];
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 100);
?>
我的代码只适用于一部分,这是宽度,图像被调整为它的宽度但不是高度。当我调整窗口大小时,图片每次都会变小。谢谢你的时间,并对任何不好的解释感到抱歉。
如果图像的大小与您的浏览器,然后这听起来像一个CSS /造型问题 –
我没有任何CSS,它是一个不同的PHP代码,当我用image.php调整窗口它不' t worj –
第一个'imagecreatefromjpeg($ filename);'调用的结果不被使用。 –