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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts

    text onto jpg error

    Hi Guys,

    i did some pretty basic testing with GD , this code should overlay a watermark/text on uploaded images but im getting a few errors:

    part of the code:

    PHP Code:
    <?php
    $uploaddirectory 
    "uploads/".$renamedimage;

              
    // Get identifier for white
              
    $white imagecolorallocate($uploaddirectory255255255);

              
    // Add text to image
              
    imagestring($uploaddirectory35imagesy($uploaddirectory)-20'www.xxx.com'$white);
    ?>
    errors:

    PHP Code:
    Warningimagecolorallocate(): supplied argument is not a valid Image resource in /home/.castle/graham23s/www.site.com/uploadpic.php on line 78

    Warning
    imagesy(): supplied argument is not a valid Image resource in /home/.castle/graham23s/www.site.com/uploadpic.php on line 81

    Warning
    imagestring(): supplied argument is not a valid Image resource in /home/.castle/graham23s/www.site.com/uploadpic.php on line 81 
    not sure what to make of the errors exactly, does it mean the image isn't getting picked up by the gd functions?

    cheers guys

    Graham

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    The image resource has to be created with imagecreatetruecolor() before you try to use it.

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi Mate,

    i tried making a function for it:

    PHP Code:
    <?php
        
    ## watermark function
        
    watermark_image($filename,$uploaddirectory);
    ?>
    This passes the $filename of the uploaded file to get the extension

    function:

    PHP Code:
    <?php
         
    function watermark_image($filename,$uploaddirectory) { 
         
            
    ## Using GD
            ## Find out the files extension 
            
    $extension explode("."$filename); 
            
    $extension $extension[count($extension)-1]; 
            
            
    ## Make all filenames lowercase
            
    $extension strtolower($extension);    
            
              
    ## Generate image accordingly  
              
    if($extension == "jpg" || $extension == "jpeg" || $extension == "pjpeg") {
              
              
    $image imagecreatefromjpeg($uploaddirectory); 
              
                } elseif(
    $extension == "png") {        
              
              
    $image imagecreatefrompng($uploaddirectory); 
              
                } elseif(
    $extension == "gif") {
                
              
    $image imagecreatefromgif($uploaddirectory); 
                
                }  
                
              
    $white imagecolorallocate($image255255255);

              
    imagestring($image35imagesy($image)-20'www.site.com'$white);
              
              echo 
    $extension;
            
            
            }
    ?>
    this all looks ok , but when i test it, it just uploads without any errors (but doesn't overlay the text) so theres no errors to speak of, if i echo out the extension it's fine

    can you see any errors at all?

    thanks mate

    Graham

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    You aren't using any output functions like imagejpeg(). To find out where you're getting an error turn on error_reporting() and var_dump() the results of your functions.

  • #5
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Or check your apache/IIS logs to see the errors. You can't see errors in an image, but this doesn't mean there were none.

  • #6
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi Guys,

    thanks for the help i got it fixed

    Graham


  •  

    Posting Permissions

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