【发布时间】:2011-08-20 11:59:13
【问题描述】:
我有一个关于使用函数 getImage_w($image,$dst_w) 显示图像的问题,该函数获取图像 URL ($image) 和该图像的目标宽度 ($size)。然后它重新绘制图像,根据目标宽度改变其高度。
这就是函数(在 libs/image.php 文件中):
function getImage_w($image,$w){
/*** get The extension of the image****/
$ext= strrchr($image, ".");
/***check if the extesion is a jpeg***/
if (strtolower($ext)=='.jpg' || strtolower($ext)=='.jpeg'){
/***send the headers****/
header('Content-type: image/jpeg');
/**get the source image***/
$src_im_jpg=imagecreatefromjpeg($image);
/****get the source image size***/
$size=getimagesize($image);
$src_w=$size[0];
$src_h=$size[1];
/****calculate the distination height based on the destination width****/
$dst_w=$w;
$dst_h=round(($dst_w/$src_w)*$src_h);
$dst_im=imagecreatetruecolor($dst_w,$dst_h);
/**** create a jpeg image with the new dimensions***/
imagecopyresampled($dst_im,$src_im_jpg,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
imagejpeg($dst_im);
}
在一个文件 imagetest.php 我有这个代码部分:
<?php
require 'libs/image.php';
echo '<h1>HELLO WORLD : some html</h1>
<img src="'.displayImg_w('http://www.sanctius.net/wp-content/uploads/2010/05/Avatar-20.jpg',200).'">
';
过去,我使用 $_GET 参数来编写 URL 来定义图像。但是现在,我想直接在我的代码中使用这个函数。
问题是图像显示正确,但是
Hello World
浏览器不翻译 HTML 代码(我知道第一个代码已经发送了标头)但是我想知道如何正确显示图像而不影响 html 代码。并且也没有使用将图像的 URL 更改为这种不需要的形式的 get 参数:libs/image.php?image=http://www.example.com/image&width=200
【问题讨论】:
-
输入您的代码,让您的眼睛更轻松!!!