在网上找不到任何东西,所以问题出在这里:我有一个裁剪工具,我想在此页面上显示裁剪后的图像。但是因为我functions.php
有一个使用头方法的函数,所以我不得不ob_start
在我的文件中使用。这导致我的图像未显示的问题(现在是问号,而不是正确的图像)。
代码:
<?php
ob_start();
require_once("includes/session.php");
require_once("includes/connection.php");
require("includes/constants.php");
require_once("includes/functions.php");
confirm_logged_in();
require_once("includes/header.php");
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$targ_w = $_POST['w'];
$targ_h = $_POST['h'];
$jpeg_quality = 90;
$src = $_POST['image'];
$ext = end(explode(".", $_POST['image']));
switch($ext) {
case 'jpg';
$img_r = imagecreatefromjpeg($src);
$dst_r = imagecreatetruecolor($targ_w, $targ_h);
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
header('Content-type: image/jpeg');
imagejpeg($dst_r,null, $jpeg_quality);
$output = ob_get_contents();
break;
case 'png';
$img_r = imagecreatefrompng($src);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
header('Content-type: image/png');
imagepng($dst_r, null, 8);
$output = ob_get_contents();
break;
}
}
echo $output;
ob_end_clean();
?>