PHP 的 imagecreatefromstring 函数在 Amazon Linux Server 上不起作用

发布于 2024-10-18 20:09:01 字数 1944 浏览 2 评论 0原文

我创建了一个脚本,其中 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
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

满栀 2024-10-25 20:09:02

从您的代码来看,您似乎没有安装 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

半世晨晓 2024-10-25 20:09:02

您将需要对服务器的根访问权限,我认为您无法通过亚马逊的云服务获得此权限。您需要使用 --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

天冷不及心凉 2024-10-25 20:09:01

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文