使用php显示图像时出错

使用php显示图像时出错,php,Php,因此,我使用以下函数调整图像的大小 <?php $get_w = $_GET['w']; $get_h = $_GET['h']; $image = $_GET['img']; list($width, $height) = getimagesize($image); $new_width = $get_w; $new_height = $get_h; $image_p = imagecreatetruecolor($new_widt

因此,我使用以下函数调整图像的大小

<?php
    $get_w = $_GET['w'];
    $get_h = $_GET['h'];
    $image = $_GET['img'];
    list($width, $height) = getimagesize($image);
    $new_width = $get_w;
    $new_height = $get_h;
    $image_p = imagecreatetruecolor($new_width, $new_height);
    $image = imagecreatefromjpeg($image);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    header('Content-Type: image/jpeg');
    imagejpeg($image_p, NULL, 100);
 ?> 

因此,上面的代码在我的本地服务器上运行得非常完美,但当我在我的网站服务器上运行时,它显示了许多奇怪的字符(请查看下面的链接)


也许您正在使用Apache的mod_布局? 如果是这样,您将需要为库文件禁用它

将以下内容添加到Apache配置中:

LayoutIgnoreHeaderURI /path/to/gallery2/*.*
LayoutIgnoreFooterURI /path/to/gallery2/*.*


<Directory /path/to/gallery2/>
LayoutHeaderOff
LayoutFooterOff
</Directory>
LayoutIgnoreHeaderURI/path/to/gallery2/**
LAYOUTIGNOREOTERURI/path/to/gallery2/**
裁员
下岗

希望这有帮助。

您使用的是哪台服务器?可能是服务器配置问题。当打开示例url时,Chrome会将其识别为text/html,这就是为什么您会看到所有这些字符您可能会禁用fopen url包装器:@Federicogist它是一个在上运行的Apache/2.4.23Linux@MaartenvanMiddelaar你能告诉我如何启用fopen url包装器吗?你是认真地将完整图像解析为
$\u获取
参数?考虑使用$Type代替。