我有一个外部PHP文件,可以进行一些图片大小调整(image.php)。每次使用'图片'标签时,我都需要调用它,以便可以填充“src”。我如何告诉HTML文件使用外部PHP页面,以及如何在处理'image'“src”标签时使用它?如何在HTML图片标签中使用外部文件中的PHP函数?
这是即时通讯使用尝试显示图像。
我是否需要在我的'头部'部分包含一些东西?
感谢您的帮助!
<li><a href= "/intPics//1.jpg"> <img src="<?php loadImage('/intPics//1.jpg', 300,300) ?>"<div>1.jpg</div></a></li>
这是PHP文件
<?php
function imageResizer($url, $width, $height) {
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;
}
// This resamples the image
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($url);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output the image
imagejpeg($image_p, null, 100);
}
/ /works with both POST and GET
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'GET') {
imageResize($_GET['url'], $_GET['w'], $_GET['h']);
} elseif ($method == 'POST') {
imageResize($_POST['url'], $_POST['w'], $_POST['h']);
}
// makes the process simpler
function loadImage($url, $width, $height){
echo 'image.php?url=', urlencode($url) ,
'&w=',$width,
'&h=',$height;
}
?>
我发布了一些代码,也许可以帮助澄清,对不起,很难理解。我不太确定如何说出我的问题。 – bsqrd7