PHP图像大小调整是';行不通

PHP图像大小调整是';行不通,php,Php,我从PHP站点找到了以下脚本,大小为图像的一半。我使用数据库获取图像的链接。其他东西正常工作,这意味着除了这一个以外,任何地方都没有任何错误 echo "<img src='".// File and new size $filename = '$row["image"]'; $percent = 0.5; // Content type header('Content-Type: image/jpeg'); // Get new sizes list($width, $height)

我从PHP站点找到了以下脚本,大小为图像的一半。我使用数据库获取图像的链接。其他东西正常工作,这意味着除了这一个以外,任何地方都没有任何错误

echo "<img src='".// File and new size
$filename = '$row["image"]';
$percent = 0.5;

// Content type
header('Content-Type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
"'>"
echo“”
错误: 整个页面被破坏,图像链接被破坏。

希望你们能帮助我

删除这些行后,它会工作:

echo "<img src='".// File and new size

"'>"
并创建新文件,然后将其用作图像源:

// Output
$new_filename = 'new_image.jpg';
imagejpeg($thumb,$new_filename);//saves new image to a file, instead of outputting it to the screen
echo "<img src='$new_filename'>";
//输出
$new_filename='new_image.jpg';
imagejpeg($thumb,$new_文件名)//将新图像保存到文件中,而不是输出到屏幕
回声“;
试试这个,它很管用

<?php

$filename = '$row["image"]';
$percent = 0.5;

// Content type
header('Content-Type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
 $newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output

echo "<img src='".imagejpeg($thumb)."'>";
?>


标题
已删除,其他页面正在工作,但图像已损坏。我不想将图像另存为文件,因为它需要大小。若我必须使用第二种方法,是否有一种方法可以在选项卡关闭时删除创建的文件?您可以使用cronjob删除它,或者在会话结束后使用任何其他方法进行垃圾收集。还请记住,在调用
header
函数之前,不要输出任何字符。
<?php

$filename = '$row["image"]';
$percent = 0.5;

// Content type
header('Content-Type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
 $newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output

echo "<img src='".imagejpeg($thumb)."'>";
?>