Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 显示为图像的GD2 URL_Php_Gd2 - Fatal编程技术网

Php 显示为图像的GD2 URL

Php 显示为图像的GD2 URL,php,gd2,Php,Gd2,当我运行此代码时,出现以下错误: 无法显示图像“”,因为它包含错误 我在想。。。当然它不能显示,它是一个url而不是一个图像。。。嗯 一切都执行得很好,我只是得到这个黑色页面,认为url是一个图像 这种情况也发生在(某些)其他GD2编码的页面上,但不是全部 有人知道发生了什么吗 <?php $src = '../../Uploads/Gallery/drafting_site_bg_200.jpg'; $new_img = '../../Uploads/Gallery/copy_bg_20

当我运行此代码时,出现以下错误:

无法显示图像“”,因为它包含错误

我在想。。。当然它不能显示,它是一个url而不是一个图像。。。嗯

一切都执行得很好,我只是得到这个黑色页面,认为url是一个图像

这种情况也发生在(某些)其他GD2编码的页面上,但不是全部

有人知道发生了什么吗

<?php
$src = '../../Uploads/Gallery/drafting_site_bg_200.jpg';
$new_img = '../../Uploads/Gallery/copy_bg_200.jpg';

$image = imagecreatefromjpeg($src);
$image = flip($image,1,0); // flips horizontal
//$image = flip($image,0,1); // flips vertical
//$image = flip($image,1,1); // flips both

header("Content-type: image/jpeg");
imagejpeg($image, $new_img, 80);
imagedestroy($image);

function flip($i,$h=1,$v=0) {
$width = imagesx($i);
$height = imagesy($i);
$temp = imagecreatetruecolor($width,$height);
imagecopy($temp,$i,0,0,0,0,$width,$height);
if ($h==1) {
for ($x=0 ; $x<$width ; $x++) {
imagecopy($i, $temp, $width-$x-1, 0, $x, 0, 1, $height);
}
imagecopy($temp,$i,0,0,0,0,$width,$height);
}
if($v==1) {
for ($x=0; $x<$height ; $x++) {
imagecopy($i, $temp, 0, $height-$x-1, 0, $x, $width, 1);
}
}
return $i;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org   /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>

无标题文件

首先,您不需要html,因为您的输出是jpeg。 您错过了
@imagecreatefromjpeg
上的
@
。 但是您的问题是输出文件名不能与
头一起使用。图像将成功创建,但您会收到一个错误

文件名

The path to save the file to. If not set or NULL, 
the raw image stream will be outputted directly.
您可以保存文件或使用
标题打印文件。所以应该插入null。这对我有效,但不会存储您的更改:

<?php
$src = '../../Uploads/Gallery/drafting_site_bg_200.jpg';

$image = imagecreatefromjpeg($src);
$image = flip($image,1,0); // flips horizontal
//$image = flip($image,0,1); // flips vertical
//$image = flip($image,1,1); // flips both

header("Content-type: image/jpeg");
imagejpeg($image, null, 80);
imagedestroy($image);

function flip($i,$h=1,$v=0) {
    $width = imagesx($i);
    $height = imagesy($i);
    $temp = imagecreatetruecolor($width,$height);
    imagecopy($temp,$i,0,0,0,0,$width,$height);
    if ($h==1) {
        for ($x=0 ; $x<$width ; $x++) {
            imagecopy($i, $temp, $width-$x-1, 0, $x, 0, 1, $height);
        }
        imagecopy($temp,$i,0,0,0,0,$width,$height);
    }
    if($v==1) {
        for ($x=0; $x<$height ; $x++) {
            imagecopy($i, $temp, 0, $height-$x-1, 0, $x, $width, 1);
        }
    }
    return $i;
}

?>

我在想。。。当然它不能显示,它是一个url而不是一个图像。。。嗯

用这条线

header("Content-type: image/jpeg");
您告诉浏览器,他在这之后收到的数据是JPEG图像的数据–因此,如果您不打算在这之后发送图像数据,则该行没有位置


只需删除它,PHP就会再次发送其默认内容类型
text/html

为什么您的图像包含html标记?谢谢@CBroe您的评论为我指明了正确的方向。通过删除“header(“Content-type:image/jpeg”);”行,我再次向前移动。好的,我添加了这个作为(简短的)答案。我需要存储更改。我想保存文件,而不是显示它。这最终将成为图像上传表单的一部分。我对编码并不陌生,但我对GDlib是新手。谢谢:)谢谢@CBroe。。。我正在发布“我的”答案,而你发布了这个。你给我指出了正确的方向,所以。。。给你分。非常感谢。也许你也可以帮我解决一个相关的问题。