1、文件 getimage.html
复制代码 代码示例:
<!DOCTYPE html>
<html>
<head>
<title>Get Image From Web</title>
</head>
<body>
<form method = "post" action = "getimage.php">
<label for="URL">URL:</label>
<input type="text" name="url" />
<input type="submit" name="submit" value="Get IMG" />
</form>
</body>
</html>
2、文件 getimage.php
复制代码 代码示例:
<?php
// set up variable
$url = $_REQUEST['url'];
// echo "<p> 8 ".$url."<br /></p>";
$ext = substr($url, strrpos($url, '.')+1);
// echo '<p> 9 '.$ext.'<br /></p>';
$filename = substr($url, strrpos($url, '/')+1, -(strlen($ext) + 1));
// echo '<p> 10 '.$filename.'<br /></p>';
if ($ext == 'jpg') {
$im = imagecreatefromjpeg($url);
if ($im) {
// echo '<p>created image handle<br /></p>';
$width = imagesx($im);
$height = imagesy($im);
$x = $width/2;
$y = $height/2;
$dst = imagecreatetruecolor($x, $y);
imagecopyresampled($dst, $im, 0, 0, 0, 0, $x, $y, $width, $height);
header("Content-Type:image/jpeg");
// imagejpeg($dst, 'imgdst.jpg');
imagejpeg($dst);
imagedestroy($dst);
imagedestroy($im);
// echo '<img src="imgdst.jpg" width="300">';
}
}
?>
说明:
将收到的url中的网页转换为图片,缩放后再显示到浏览器。