[英]PHP - Script using imagepng won't save file and then display it
我正在尝试加载图像,对其进行编辑,保存,然后从在IMG标签内调用的脚本中进行显示。 如果我只想显示图像,脚本可以工作,并且确实可以保存图像。 但是它不会保存然后显示。 有人知道我在做什么错吗? 任何帮助将不胜感激。
<?php
header('Content-Type: image/png');
$file_location = "test.png";
if (file_exists($file_location)) {
$img_display = @imagecreatefrompng($file_location);
// This section of code removed as doesn't affect result
imagepng($img_display, $file_location);
chmod($file_location, 0777);
imagepng($img_display);
imagedestroy($img_display);
}
?>
尝试此操作,并检查您的文件夹是否具有保存图像的权限。 chmod 777肯定可以。
<?php
header('Content-Type: image/png');
$file_location = "test.png";
if (file_exists($file_location)) {
$img_display = imagecreatefrompng($file_location); // Create PNG image
$filename = $file_location + time(); // Change the original name
imagepng($img_display, $filename); // Saves it with another name
imagepng($filename); // Sends it to the browser
imagedestroy($img_display); // Destroy the first image
imagedestroy($filename); // Destroy the second image
}
尝试这个:
ob_start();
imagepng($img_display);
$contents = ob_get_clean();
file_put_contents($file_location, $contents);
echo $contents;
imagedestroy($img_display);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.