我已经花了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?key1=value1&key2=value2&...
。
尽管由于这是HTML,所以您必须使用&
而不是plain &
,例如:
<?php
// ...
echo "<img src='image.php?bag=$bag&art=$art&x1=$x1'>"
然后,您可以image.php
通过访问$_GET
superglobal从中检索它们:
$bag = $_GET['bag'];
$art = $_GET['art'];
// and so on
如果我理解正确,您也尝试使用某些方法,require_once
而不是通过加载图像<img src='image.php'
。这将具有直接将图像数据转储到HTML文件中的效果,这将无法正确呈现(尽管可以内联加载图像,但我不建议您使用此方法)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句