Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Location
    Reading, Pennsylvania
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    imagecreatefromstring (From file) Error - How to fix/go around?

    I'm creating my own simple image manipulation library.

    So far so good. It accepts uploaded image files, base64 encoded strings, and URLs. Well, I haven't tested base64 strings and URLs, because right now I'm stuck on file uploads.

    http://ajango.org/.dev/phpImageLibrary/ is where you can see the library in action by submitting an image. Files submitted are not uploaded to the server, but instead are accessed via the '/tmp' folder using realpath().

    The trouble that I'm having is that I can't seem to use convertToGIF(), and the other conversion functions at that.

    $this->imageResource points to the ORIGINAL PHP GD image that I create using the tmp file and imagecreatefromstring().

    If I can create the original image from a string, how come I can't convert the image using imagegif() and recreate the image from the outputted file of it?

    You can view the source of the library here.

    I tried uploading a PNG to be converted into a GIF.

    Can anybody tell me what's going on with this?

    The Errors:
    Warning: imagecreatefromstring(): Empty string or invalid image in /home/ajangox1/public_html/.dev/phpImageLibrary/lib.php on line 70

    Warning: Cannot modify header information - headers already sent by (output started at /home/ajangox1/public_html/.dev/phpImageLibrary/lib.php:70) in /home/ajangox1/public_html/.dev/phpImageLibrary/lib.php on line 84

    Warning: imagegif() expects parameter 1 to be resource, boolean given in /home/ajangox1/public_html/.dev/phpImageLibrary/lib.php on line 95

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Posts
    456
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Empty string or invalid image
    How are you validating your images?

    $im = $imagecreatefromstring($FILE);
    $valid = ($im !== FALSE);
    imagedestroy($im);
    return $valid;
    ?????
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #3
    New to the CF scene
    Join Date
    Apr 2013
    Location
    Reading, Pennsylvania
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I believe your looking at the wrong method. I don't use imagedestroy() except for in the outputImage() method. I'm talking about the methods:

    -convertToJPG
    -convertToGIF
    -convertToPNG

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Posts
    456
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Warning: imagecreatefromstring(): Empty string or invalid image in /home/ajangox1/public_html/.dev/phpImageLibrary/lib.php on line 70
    Code:
            public function convertToJPG($quality=60){
                if(!$this->imageResource){
                    return 0;
                }
                
                $imageData;
                ob_start();
                    imagejpeg($this->imageResource,null,$quality);
                    $imageData = ob_get_contents(); 
                ob_end_clean();
                
                $this->imageResource = imagecreatefromstring($imageData);
                $this->imageType = "jpg";
            }
    According to my editor 'line 70' which is creating the initial error in the one marked in red 'ob_end_clean();' so you should probably test the $imageData string going into the main function to verify. Obviously it's either 'Empty or invalid' or you wouldn't be getting the error.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •