andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Add text to image

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Drop Shadowed Thumbnail Creator
View previous topic :: View next topic  
Author Message
Pate
Newbie


Joined: 29 Apr 2004
Posts: 4

PostPosted: Thu Apr 29, 2004 12:19 pm    Post subject: Add text to image Reply with quote

Hello,

Just wanted to start by telling you I really like your class. Made my life so much better! Wink

I got a question thou. Is there a good way to add a small text to the image with shadow?
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Fri Apr 30, 2004 3:58 am    Post subject: Re: Add text to image Reply with quote

Pate wrote:
Hello,

Just wanted to start by telling you I really like your class. Made my life so much better! Wink

I got a question thou. Is there a good way to add a small text to the image with shadow?


Hi Pate - welcome to the board!

Glad you like the class! Smile

There is not built in way with the class to add text. However, you could use imagechar or imagettftext functions to write on the image:

http://www.php.net/manual/en/function.imagechar.php
http://www.php.net/manual/en/function.imagettftext.php

If this is something you're going to do a lot of, then perhaps you might want to extend the class, in much the same way that class.originaldropshadow.php has, only you'll include methods that allow you to write to the image before you save/display it.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Pate
Newbie


Joined: 29 Apr 2004
Posts: 4

PostPosted: Fri Apr 30, 2004 4:10 am    Post subject: Reply with quote

Thanks for your fast reply. It's really great that you keep support on a product that's offered for free! Smile

Anyway, I tried working abit with it and using this code to generate the dropshadow on the fly:

PHP:
<?php $ds = new dropShadow(FALSE);
        
$ds->setShadowPath('/home/path/to/shadows/');
        
$ds->loadImage($filename);
        
$ds->resizeToSize(120,0);
        
$ds->applyShadow('EFEFEF');
        
$ds->showShadow('jpg'); ?>


In what part of the class can I add the addtext part?

I tried making a new function to your class, but that didnt work out very well. Smile

PHP:
<?php $ds->addText("Test"); ?>


and in the class:

PHP:
<?php function addText($text)
    {
        
$this->_debug('addText'"Adding text $text");
        return (
$this->_addText($text));
    }

    function 
_addText($text)
    {
        if (
$this->_imgOrig == NULL)
        {
            
$this->_debug($function'The original image has not been loaded.');
            return 
FALSE;
        }
        if (
$this->_imgFinal$this->flushImages(1);
      
    
$black imagecolorallocate($im000);
    
$white imagecolorallocate($im255255255);
    
$wdtcolor imagecolorallocate($im244080);

    
//Drawing text on the image
    
imagestring($im5110100$text$wdtcolor); 
  } 
?>


If you could point me in the right direction, it would be great. If you are offering paidsupport, I suppose I could agree on that as well. Laughing
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Fri Apr 30, 2004 5:02 am    Post subject: Reply with quote

Hi Pate,

Nice looking website you've got there, by the way. Smile (but the 'back to top' link doesn't seem to work.)

Pate wrote:
Thanks for your fast reply. It's really great that you keep support on a product that's offered for free! Smile


Yep, free is nice. Smile (Not opposed to people donating money if they want to, though! Laughing )

Pate wrote:
Anyway, I tried working abit with it and using this code to generate the dropshadow on the fly:

PHP:
<?php $ds = new dropShadow(FALSE);
    
$ds->setShadowPath('/home/path/to/shadows/');
    
$ds->loadImage($filename);
    
$ds->resizeToSize(120,0);
    
$ds->applyShadow('EFEFEF');
    
$ds->showShadow('jpg'); ?>


In what part of the class can I add the addtext part?


Well, your call to adding text should come before you show the finished result. To be honest, you're probably better of to apply the text before you do the shadow, because you can then correct determine positioning. IF you did this after the shadow was applied you'd have to take into consideration the width of the shadow images to position the text correctly. So have your code something like:

PHP:
<?php $ds = new dropShadow(FALSE);
    
$ds->setShadowPath('/home/path/to/shadows/');
    
$ds->loadImage($filename);
    
$ds->resizeToSize(120,0);
    
$ds->addText(1010'Add This Text');
    
$ds->applyShadow('EFEFEF');
    
$ds->showShadow('jpg'); ?>


You can see there that the method takes three parameters. This will be the x/y position and the text you want to add. Naturally, you could extend this to include text size and colour.

Then you were on the right lines with the addText method. You can easily just add it directly into the dropshadow class if you want. Bear in mind, though, that if I ever update the class and you want to implement it, then you'd have to extract your code and put it into the new class. If you just extend the class then you probably wouldn't have to make any changes.

Anyway, on to the method...

PHP:
<?php function addText($x$y$text)
{
    
$this->_debug('addText'"Adding text '$text'");
    if (
$this->_imgFinal == NULL)
    {
        
$this->_debug($function'The image has not been processed.  Text can only be added to a processed image.');
        return 
FALSE;
    }
      
    
$black imagecolorallocate($this->_imgFinal000);
    
$white imagecolorallocate($this->_imgFinal255255255);
    
$wdtcolor imagecolorallocate($this->_imgFinal244080);

    
//Drawing text on the image
    
imagestring($this->_imgFinal5$x$y$text$wdtcolor); 
?>


What I've done there is removed the call to flush the images. I've also applied the text to the '_imgFinal' image - you had it trying to be applied to a non-existing 'im' image resource. You can change _imgFinal to _imgOrig or _imgShadow, depending on what image you wanted to write to.... you could even update the method so that it takes a new parameter which determines what image resource to use.

Now, I haven't tested that out - so be warned! But give it a whirl and see what result it gives you.

Pate wrote:
If you could point me in the right direction, it would be great. If you are offering paidsupport, I suppose I could agree on that as well. Laughing


That all depends on how much you're willing to pay. Wink Support on this board is generally free. If someone wants me to write a new script for them, or extend classes for their particular needs, then I might charge some money (a guy's gotta eat, right?). Otherwise, consider it free and open to friendly donations, should the desire to support the site take you. Very Happy

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Pate
Newbie


Joined: 29 Apr 2004
Posts: 4

PostPosted: Fri Apr 30, 2004 2:35 pm    Post subject: Reply with quote

I'll assume you take Paypal as donations? Give me a URL and you can expect some cash in the near future. Smile Maybe not that much, but I want to show my appricaition in some way...

Thanks for your comments on the website by the way. Always good to hear. Smile
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Sat May 01, 2004 12:23 pm    Post subject: Reply with quote

Hi Pate,

That's very nice of you to even offer!!

I actually have a PayPal link from the homepage. Just click on the little elephant (at the top of the page) to get there.

Don't forget to let us know if you're successful in adding text to your image. Smile

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Pate
Newbie


Joined: 29 Apr 2004
Posts: 4

PostPosted: Sun May 02, 2004 3:55 pm    Post subject: Reply with quote

It's added allready. With some customization to the code I now have a transparent background and a number showing how many comments there are for that specifical image. Look a bit down or in the photo section to find a image with the text added. (Link in profile. Very Happy )

Thanks alot, sending you a little paypal gift! Smile
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
adjamlotfi
Newbie


Joined: 23 Feb 2004
Posts: 8

PostPosted: Mon Aug 02, 2004 11:38 am    Post subject: Reply with quote

Hi;

I would like to test adding text to images but the path as shown in the scripts is not valid in windows environment.

how to fix that

thanks
adjamlotfi@yahoo.fr Very Happy Very Happy Very Happy Very Happy
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Aug 02, 2004 4:56 pm    Post subject: Reply with quote

Well, you would make it whatever IS valid for your paths. I personally use Windows XP with Apache and PHP, and so have no problems using something like:

$ds->setShadowPath('E:/www/images/shadow/');

Or something like:

$ds->setShadowPath($_SERVER['DOCUMENT_ROOT'] . '/images/shadow/');

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Drop Shadowed Thumbnail Creator All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group