简体   繁体   中英

PHP's imagecreatefromstring function not working on Amazon Linux Server

I have created a script in which ai have to create a image at runtime using a 64bitencoded string .im 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 在此处输入图片说明

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

From your code, it seems that you dont have the GD extension installed. Please check the phpinfo output and look for the GD extension

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM