Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-27-2007, 09:48 PM   PM User | #1
graham23s
Regular Coder

 
Join Date: Jul 2007
Location: Scotland
Posts: 134
Thanks: 12
Thanked 0 Times in 0 Posts
graham23s is an unknown quantity at this point
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
graham23s is offline   Reply With Quote
Old 11-27-2007, 11:13 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
The image resource has to be created with imagecreatetruecolor() before you try to use it.
Inigoesdr is offline   Reply With Quote
Old 11-27-2007, 11:28 PM   PM User | #3
graham23s
Regular Coder

 
Join Date: Jul 2007
Location: Scotland
Posts: 134
Thanks: 12
Thanked 0 Times in 0 Posts
graham23s is an unknown quantity at this point
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
graham23s is offline   Reply With Quote
Old 11-28-2007, 04:16 AM   PM User | #4
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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.
Inigoesdr is offline   Reply With Quote
Old 11-28-2007, 04:49 PM   PM User | #5
aedrin
Senior Coder

 
Join Date: Jan 2007
Posts: 1,648
Thanks: 1
Thanked 58 Times in 54 Posts
aedrin will become famous soon enough
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.
aedrin is offline   Reply With Quote
Old 11-29-2007, 10:59 PM   PM User | #6
graham23s
Regular Coder

 
Join Date: Jul 2007
Location: Scotland
Posts: 134
Thanks: 12
Thanked 0 Times in 0 Posts
graham23s is an unknown quantity at this point
Hi Guys,

thanks for the help i got it fixed

Graham
graham23s is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:01 PM.


Advertisement
Log in to turn off these ads.