-1
下面的代码自己执行的很好,但是当我用表单元素语句包装它时,我得到错误“调用flipit.php中的未定义函数翻转行11,14或17单选按钮我在表单中选择)。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;
}
header('Location: showme.php'); // page displays the image
?>
代码...
<?php
$editFormAction = $_SERVER['PHP_SELF'];
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { // if form is submitted
$src = '../../Uploads/Gallery/drafting_site_bg_200.jpg';
$new_img = '../../Uploads/Gallery/copy_bg_200.jpg';
$image = imagecreatefromjpeg($src);
if ((isset($_POST["Flip"])) && ($_POST["Flip"] == "Horizontal")) {
$image = flip($image,1,0); // flips horizontal
}
if ((isset($_POST["Flip"])) && ($_POST["Flip"] == "Vertical")) {
$image = flip($image,0,1); // flips vertical
}
if ((isset($_POST["Flip"])) && ($_POST["Flip"] == "Both")) {
$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;
}
header('Location: showme.php'); // page displays the image
}
?>
问题似乎是你的函数定义是你的第一个'if'代码块的一部分 - 如果条件块试着把它放在外面。而且,请为你所信任的任何神的爱 - 正确地缩进你的代码,以便它直观地看到它的部分是什么块的一部分。习惯于用你现在编写的任何一段代码来做这件事 - 否则你将会遇到一些问题,你不知道迟早会发生什么。 – CBroe 2014-09-04 14:39:11
再次感谢@CBroe。发布这个作为你的答案,你有我的投票。 – Kuya 2014-09-04 14:45:33