【发布时间】:2014-12-12 02:51:45
【问题描述】:
我花了 4 天时间来解决一个属问题。我是新手。
我的一般问题是
<?php
$art = $_POST['source_file'];
$bag = $_POST['destination_file'];
$x1=100;
$y1 = 400;
$x2 = 700;
$y2 = 800;
?>
<img src = 'image.php'>
<?php
// other codes
?>
我需要将 $bag, $art, $x1, $y1, $x2, $y2 传递给 image.php 并使用它来创建 GD 图像。如果我使用变量的值并在 image.php 中说明,它可以工作。如果我按原样使用 $a(我认为该变量是 image.php 的全局变量),它就不起作用。
如果我将 img src = 'image.php' 替换为有效的 php require_once('image.php'),屏幕上不会显示任何内容,因为未创建图像并且由于 image.php 中声明的标题,页面的行为作为错过/未找到的图像。
Image.php的内容是:
<?php
$bag=$_GET['bag'];
// this is the variable to be passed either by get or by post or by global variable
header ('Content-Type: image/png');
//$im = imagecreatefrompng('./bag_templates/bag1.PNG');
//this comented $im works. I need to pass content from variable
$im = imagecreatefrompng($bag);
//$source = imagecreatefromJPEG('./thumbnails/2014_12_10_23_53_48.JPG');
$source = imagecreatefromJPEG($art);
//$art variable must be passed from main page
list($source_width, $source_height)=getimagesize($art);
//variables x1,y1,x2,y2 must be passed from main file.
$frame_l = $x2-$x1;
$frame_h = $y2-$y1;
$start_x = $x1 + (($frame_l -$source_width)/2);
$start_y = $y1 + (($frame_h -$source_height)/2);
$destination = imagecreatefrompng($bag);
imagecopy($destination, $source, $start_x, $start_y, 0, 0, $source_width, $source_height);
//bool imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )
imagepng($destination);
imagedestroy($destination);
?>
应该从主文件传递的变量:
$bag
$art
$x1, $y1
$x2, $y2
这个图像的结果(合并图像 - $destination)应该显示在主页上 - 简单地调用 image.php 作为 -
img src ='image.php'
【问题讨论】:
-
嗨,您的目标是简单地将变量传递给 image.php?是对的吗?对不起,我对你试图做的事情有点困惑。正如您所提到的,当您使用一次 image.php 时,该文件丢失了。另外,您不能将 php 用作 src 选项。你能解释一下 image.php 是什么吗?
-
您指的是
$a、$b和$c,它们在当前文本中已不存在 -
@olleh 我的理解是,是的,这就是目标。并且他们尝试使用
require_once('image.php')而不是<img src='image.php'>,这显然无法正确显示。