【问题标题】:imagecreatefrompng: info being sent but not working properlyimagecreatefrompng:正在发送信息但无法正常工作
【发布时间】:2014-03-31 05:00:58
【问题描述】:

好吧,我有一段时间没有编码了,所以我一直在拼凑代码。无论如何,我正在创建一个站点,它将 Post 数据从 index.php 发送到 Boutique.php。 Boutique.php 页面上有 imagecreatefrompng

当您从 index.php 发送表单数据时,它将从 mysql 数据库中选择您在索引中选择的选项,发送该选项,从数据库中获取链接并将链接发送到 Boutique.php。

现在我已经开始工作了,当我包含页面而不添加标签时,我从精品.php 页面回显图像链接标签,链接 url 显示,所以代码本身正在发送适当地。但它也显示了乱码:

ÿØÿàJFIFÿþ>创建者:gd-jpeg v1.0(使用 IJG JPEG v62),默认质量 ÿÛC

甚至当我把页面中的代码损坏了,但是图片链接正在发送中。

精品.php

<?php
header('Content-Type: image/png');
ob_start();
$image_data = ob_get_clean();
session_start();

mysql_connect('localhost', 'user', 'pw')
or die('Could not connect: ' . mysql_error());
mysql_select_db('data') or die('Could not select database');

$GetTanTable = "SELECT * FROM Pants  WHERE maincolor='Tan'";

$GetTan = mysql_query($GetTanTable) or die('Query failed: ' . mysql_error());

while ($RowTan = mysql_fetch_array($GetTan, MYSQL_ASSOC)) 
{

$GetPantsImage = $RowTan['image'];

if(isset($_POST['PTsubmit']) && $RowTan['subcolor'] == $_POST['PTan'])
{
$horizontal = 'right';
$vertical = 'bottom';

$watermark = imagecreatefrompng($GetPantsImage);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$src = $_GET["src"];
}
}
$image = imagecreatetruecolor(250, 500);
$black = imagecolorallocate($image, 0, 0, 0);
imagecolortransparent($image, $black);
imagealphablending($image, true); 
imagesavealpha($image, true);  
$horizontal = 'right';
$vertical = 'bottom';
switch ($horizontal) {
default:
$dest_x = $size[0] - 50;
}
switch ($vertical) {
default:
$dest_y = $size[1] - 50;
}

imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width,$watermark_height);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>

现在,即使代码发送正确,但当我删除所有 if、while 语句并将常规 http:// 代码放入 $GetPantsImage 时,它​​仍然有效。所以我真的不明白

代码在以下情况下起作用:我取出 if/while 语句,并将实际的 url 放入数据集中

【问题讨论】:

  • 当您在文件顶部声明 header('Content-Type: image/png'); 时,您正在输出带有 imagejpeg() 的图像。您可能正在寻找imagepng()
  • 我希望这会解决它,但现在它只是为 PNG 提供乱码
  • 使用$RowTan['image'] 变量设置后$GetPantsImage 的值是多少?
  • 当我在 Boutique.php 上回显它时,它是图像 url(这正是它应该是的)但由于某种原因它就像 imagecreatefrompng 没有接受它。
  • 但是我只是将带有引号的 url 放入数据库中。并返回错误警告:imagecreatefrompng('sugarbabiesblog.com/images/thumbs/maykhakipants.png') 所以它正在获取 url 但不显示图像

标签: php mysql


【解决方案1】:

您尝试处理的文件是在远程服务器上还是本地服务器上?

如果它是远程的,那么你必须指定完整的 url:

http://sugarbabiesblog.com/images/thumbs/maykhakipants.png

(在您的示例中,您省略了 http)

如果是本地的,你想省略域名:

/images/thumbs/maykhakipants.png

这里有一些见解:I can't open this PNG file with imagecreatefrompng()

【讨论】:

  • 当我从数据库链接中删除 http:// 时,我收到了警告:imagecreatefrompng(upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png) [function.imagecreatefrompng]:无法打开流:第 21 行的 /home3/zacmaur/public_html/nash/boutique.php 中没有这样的文件或目录
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-01
  • 2012-12-13
  • 1970-01-01
  • 2020-02-03
  • 1970-01-01
  • 2017-10-05
相关资源
最近更新 更多