PHP 的 imagecreatefromstring 函数在 Amazon Linux Server 上不起作用
我创建了一个脚本,其中 ai 必须使用 64 位编码字符串在运行时创建图像。im 使用 PHP 的 imagecreatefromstring 函数,但它可以在我的基于 Windows XAMPP 的 PHP 中工作,但不能在我部署在 Amazon 云上运行的云端应用程序上工作Linux 的 SUSE 版本。
你能给我任何建议来解决这个问题吗? 或者是否有任何其他函数能够从传递给它的编码字符串创建图像。
感谢 adv
我正在使用以下代码
<?php
require ('../dbconfig/dbConfig.php');
$gameId = $_POST["gameId"];
$username = $_POST['email'];
$imagedata = $_POST['imagedata'];
$uploaddir = './../blogdata/i/';
$countSql = mysql_query("select max(_id) as fileName from blog_data ");
while($rowCommentData = mysql_fetch_assoc($countSql))
{
$num = $rowCommentData["fileName"];
$file = ++$num.".png";
$filedb = $uploaddir .$file;
}
/* $imagedata= 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';*/
$imagedata= base64_decode($imagedata);
if(($img = @imagecreatefromstring($imagedata)) !== FALSE)
{
if(imagepng($img,$filedb))
{
imagedestroy($img);
$sql="Insert into blog_data (game_id,text,type,username)".
"Values('$gameId','$file','i','$username')";
$result=mysql_query($sql);
if($result == 1)
{
echo $file;
}
else
{
echo "error2";
}
}
else {
echo "error1";
}
}
else
{
echo "error0";
}
?>
通过运行 PHP info 那里我得到了这个信息
I have created a script in which a i have to create a image at runtime using a 64bitencoded string .i m using imagecreatefromstring function of PHP but it works in my Windows XAMPP based PHP , but not on my cloud side applications which i deployed on Amazon cloud running SUSE version of Linux.
Can u give me any suggestion to overcome the problem.
Or is there any other function which is capable to create the image from the encoded string passed to it.
Thanks in adv
I am using following code
<?php
require ('../dbconfig/dbConfig.php');
$gameId = $_POST["gameId"];
$username = $_POST['email'];
$imagedata = $_POST['imagedata'];
$uploaddir = './../blogdata/i/';
$countSql = mysql_query("select max(_id) as fileName from blog_data ");
while($rowCommentData = mysql_fetch_assoc($countSql))
{
$num = $rowCommentData["fileName"];
$file = ++$num.".png";
$filedb = $uploaddir .$file;
}
/* $imagedata= 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';*/
$imagedata= base64_decode($imagedata);
if(($img = @imagecreatefromstring($imagedata)) !== FALSE)
{
if(imagepng($img,$filedb))
{
imagedestroy($img);
$sql="Insert into blog_data (game_id,text,type,username)".
"Values('$gameId','$file','i','$username')";
$result=mysql_query($sql);
if($result == 1)
{
echo $file;
}
else
{
echo "error2";
}
}
else {
echo "error1";
}
}
else
{
echo "error0";
}
?>
By running PHP info there i got this information
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从您的代码来看,您似乎没有安装 GD 扩展。请检查
phpinfo
输出并查找 GD 扩展From your code, it seems that you dont have the GD extension installed. Please check the
phpinfo
output and look for the GD extension您将需要对服务器的根访问权限,我认为您无法通过亚马逊的云服务获得此权限。您需要使用 --with-gd 标志重新编译 php。
http://www.php.net/manual/en/image.installation.php
You will need root access to the server, which I don't think you get with Amazon's cloud service. You will need to recompile php with --with-gd flag.
http://www.php.net/manual/en/image.installation.php
PHP 需要安装并加载 libgd 扩展。检查 phpinfo() 是否存在。您可能可以通过 yum 安装它。该软件包应名为 php5-gd
The PHP needs to have the libgd extension installed and loaded. Check phpinfo() if it's there. You probably can install it via yum. The package should be called php5-gd