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.


Use dropshadow class with templates

 
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
Maarten Martens
Newbie


Joined: 26 Jan 2004
Posts: 7

PostPosted: Mon Jan 26, 2004 4:11 pm    Post subject: Use dropshadow class with templates Reply with quote

Hello Andy,

I recently discovered your drop shadow class and thought it might be THE solution for my problem. I'm currently building a website using PHP, MYSQL and the SMARTY templating engine. I installed your class, but after 3 hours of toying with it without results, I gave up on it. I'm not that experienced with OO programming in PHP, though I understand the basics.
I'm programming a website where the user may switch between different templates, so saving the images with a shadow and a background color was out of the question, as it would not work for other background colors.

I was reading this forum and looked into your solution of showing the pictures on the fly, without saving them (http://php.amnuts.com/forums/viewtopic.php?t=20). But after copying the "dosave" part into the function I kept on stumbling on errors (function saveImage is unknown, eg.).

An other question I had was using your class with templates. You see, the way the templating works is you get all DB info, then you store them with the template class in template vars and you send them to the template file (the HTML file). I also do this with the pictures. Their path is stored in my db, so I take out the path, put it in a templata var and send it to the template where it will then show up on my screen. Is it possible to add a shadow on the fly (without altering the original pic on HD), and send this version into the template engine? Do you have any experience in this field? Does anybode out there has any experience with the dropshadow class and templating?

Any help or tips are greatly appreciated! This class seems so close to the perfect solution, it just has to work ... some way or another!

Cheers,
Maarten Martens
Back to top
View user's profile Send private message
amnuts
Site Admin


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

PostPosted: Tue Jan 27, 2004 3:51 am    Post subject: Re: Use dropshadow class with templates Reply with quote

Hi Maarten, and welcome to the board!

Maarten Martens wrote:
I recently discovered your drop shadow class and thought it might be THE solution for my problem. I'm currently building a website using PHP, MYSQL and the SMARTY templating engine. I installed your class, but after 3 hours of toying with it without results, I gave up on it.


Did you try just the standard example file that comes with the class? Do you have GD installed and is it of a significant version? (2.0.1+)

Maarten Martens wrote:
I was reading this forum and looked into your solution of showing the pictures on the fly, without saving them (http://php.amnuts.com/forums/viewtopic.php?t=20). But after copying the "dosave" part into the function I kept on stumbling on errors (function saveImage is unknown, eg.).


That's because those snippets on that thread use an older version of the class. The saving functions are now saveFinal and saveShadow, which save just the resized thumbnail or the resized thumbnail with the dropshadow effect.

However, if you are wanting to generate your images on the fly then you don't want to be saving them at all.

Maarten Martens wrote:
An other question I had was using your class with templates. You see, the way the templating works is you get all DB info, then you store them with the template class in template vars and you send them to the template file (the HTML file). I also do this with the pictures. Their path is stored in my db, so I take out the path, put it in a templata var and send it to the template where it will then show up on my screen. Is it possible to add a shadow on the fly (without altering the original pic on HD), and send this version into the template engine? Do you have any experience in this field? Does anybode out there has any experience with the dropshadow class and templating?


Well, not having worked with smarty before (I know, I know.. I keep meaning to check it out, but always seem over-the-top for any application where I'd need a template), so you're going to have to tweak this a bit, but...

Say I had a variable which had the location of the image I want to show:

$img = 'myimage.jpg';

And it gets put into the html like:

<img src="<?php echo $img; ?>" title="my image">

Okay, but now I decide I don't want to display that image directly, but instead want to resize my original image to have a width of 50px (but we want the height to be proportional to the width) and have a drop shadow effect, then we might have something like this:

$img = 'showimage.php?img=myimage.jpg&w=50&shadow=1';

As you can see, instead of directly echoing the image name, now we give the name of a script with some parameters. So now we have to write a little script that processes that request for an image, which might look something like:

PHP:
<?php

    
require dirname(__FILE__) . '/class.dropshadow.php';

    
$ds = new dropShadow(false);
    
$ds->setShadowPath(dirname(__FILE__) . '/shadows/');
    
$ds->loadImage($_GET['img']);
    
$ds->resizeToSize($_GET['w'], 0);
    if (
$_GET['shadow'] == 1) {
        
$colour = (isset($_GET['bgcolour'])) ? $_GET['bgcolour'] : 'FFFFFF';
        
$ds->applyShadow($colour);
        
$ds->showShadow('jpg'80);
    } else {
        
$ds->showFinal('jpg'80);
    }    

?>


and save that as a file called showimage.php.

As you might be able to tell from that script, I can also pass another parameter in the query string called 'bgcolour' which will be the background colour for the shadow. So I could make my variable look like this:

$img = 'showimage.php?img=myimage.jpg&w=50&shadow=1&bgcolour=CCCCCC';

or if I have another template:

$img = 'showimage.php?img=myimage.jpg&w=50&shadow=1&bgcolour=3DF567';

Do you see how that works? Of course, if you wanted to just display the image resized without a shadow effect, then make 'shadow=1' into 'shadow=0'.

That should give you enough to go on for now. Any other problems, just post up!

Regards,

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


Joined: 26 Jan 2004
Posts: 7

PostPosted: Tue Jan 27, 2004 3:02 pm    Post subject: Reply with quote

Hello Andy,

First of all, thanks a lot for your professional info. I added all your code, almost literally, and there are no errors. However, the images still don't appear on screen.

I don't know if I installed GD, I use an installation package called php5xampp-dev (php and friends - from hotscripts). Where can I find GD?

I don't know if this is the problem. However, I have a question. After I retrieve all my data from the DB, I send them through the smarty engine and into a TPL (template) file (this is a HTML file). Now, looking at your solution, instead of placing the <img=directory/image.jpg> I have to call another php file like this : <img src="'includes/showimage.php?img=../images/news_images/7.jpg&w=100&shadow=1&bgcolour=CCCCCC'">. The link you see is indeed correctly generated and placed withing the TPL file, but I have a feeling the showimage.php just isn't called. I mean, it seems this part is seen as a complete link to an image, instead of a link to a file. This is probabely because the actual template isn't a php extension file but I tpl file?? Do you have any idea?

I checked the smarty docs, but haven't found a real solution, maybe I should ask it over on their forum, as this might be more of a template issue? Or am I mistaking?

If I don't have GD ... Should I get an error in my browser?

Thank you in advance,
Maarten
Back to top
View user's profile Send private message
amnuts
Site Admin


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

PostPosted: Tue Jan 27, 2004 3:36 pm    Post subject: Reply with quote

Maarten Martens wrote:
I don't know if I installed GD, I use an installation package called php5xampp-dev (php and friends - from hotscripts). Where can I find GD?


Having never heard of that before I checked their website - nice little package there! Wasn't sure if you installed the windows or linux version, but you can do a simple check in PHP to see what's installed and able to be used. In a file called 'info.php' (can be called anything you want, really), put in this line:

<?php phpinfo(); ?>

Save and view it through your web browser. It will show you all that's installed. Just scroll down and check for GD and the version.

I have only checked this script on version 4 of PHP and not 5, so I cannot guarantee it's going to work on PHP5 - though it should.

One thing I did neglect to put in the 'showimage.php' file was the content header. You should have something like:

PHP:
<?php

    
require dirname(__FILE__) . '/class.dropshadow.php';

    
$ds = new dropShadow(false);
    
$ds->setShadowPath(dirname(__FILE__) . '/shadows/');
    
$ds->loadImage($_GET['img']);
    
$ds->resizeToSize($_GET['w'], 0);
    
header('Content-type: image/jpeg'); // this is the new line
    
if ($_GET['shadow'] == 1) {
        
$colour = (isset($_GET['bgcolour'])) ? $_GET['bgcolour'] : 'FFFFFF';
        
$ds->applyShadow($colour);
        
$ds->showShadow('jpg'80);
    } else {
        
$ds->showFinal('jpg'80);
    }    

?>


Obviously you'd want to change the content-type to be whatever you output (image/jpeg or image/png).

Maarten Martens wrote:
I don't know if this is the problem. However, I have a question. After I retrieve all my data from the DB, I send them through the smarty engine and into a TPL (template) file (this is a HTML file). Now, looking at your solution, instead of placing the <img=directory/image.jpg> I have to call another php file like this : <img src="'includes/showimage.php?img=../images/news_images/7.jpg&w=100&shadow=1&bgcolour=CCCCCC'">. The link you see is indeed correctly generated and placed withing the TPL file, but I have a feeling the showimage.php just isn't called. I mean, it seems this part is seen as a complete link to an image, instead of a link to a file. This is probabely because the actual template isn't a php extension file but I tpl file?? Do you have any idea?


The fact that the TPL file isn't a php file wont make any difference. To the TPL file, the src for the image could be an image for all it knows. The showimage.php file is the only one that needs to be of a php type.

I think that putting the content type in may help you, but you could always put debugging code into the script. For example, write out a file or send yourself an email to let you know the file has been called, and possible what parameters. For example:

PHP:
<?php

    
require dirname(__FILE__) . '/class.dropshadow.php';

    
$debugging true;
    
$ds = new dropShadow(false);
    
$ds->setShadowPath(dirname(__FILE__) . '/shadows/');
    
$ds->loadImage($_GET['img']);
    
$ds->resizeToSize($_GET['w'], 0);
    if (
$debugging && (true === ($fp fopen('log.txt''w')))) {
        
fwrite($fp"Called file with the following parameters:\n\n");
        
fwrite($fpjoin("\n"explode('&'$_SERVER['QUERY_STRING'])));
        
fclose($fp);
    }
    
header('Content-type: image/jpeg');
    if (
$_GET['shadow'] == 1) {
        
$colour = (isset($_GET['bgcolour'])) ? $_GET['bgcolour'] : 'FFFFFF';
        
$ds->applyShadow($colour);
        
$ds->showShadow('jpg'80);
    } else {
        
$ds->showFinal('jpg'80);
    }    

?>


You could possibly go further by turning on the output buffer (ob_start()) and setting debugging in the class to be on, and then outputting any feedback that the class gives you, like:

PHP:
<?php

    ob_start
();
    require 
dirname(__FILE__) . '/class.dropshadow.php';

    
$debugging true;
    
$ds = new dropShadow(true);
    
$ds->setShadowPath(dirname(__FILE__) . '/shadows/');
    
$ds->loadImage($_GET['img']);
    
$ds->resizeToSize($_GET['w'], 0);
    
$buff ob_get_contents();
    
ob_end_clean();
    if (
$debugging && (true === ($fp fopen('log.txt''w')))) {
        
fwrite($fp"Called file with the following parameters:\n\n");
        
fwrite($fpjoin("\n"explode('&'$_SERVER['QUERY_STRING'])));
        if (
$buff) {
            
fwrite($fp"\nThe output from the class was:\n\n$buff");
        }
        
fwrite($fp"\n");
        
fclose($fp);
    }
    
header('Content-type: image/jpeg');
    if (
$_GET['shadow'] == 1) {
        
$colour = (isset($_GET['bgcolour'])) ? $_GET['bgcolour'] : 'FFFFFF';
        
$ds->applyShadow($colour);
        
$ds->showShadow('jpg'80);
    } else {
        
$ds->showFinal('jpg'80);
    }    

?>


You get the idea? And then when you want debugging off, just set:

$debugging = false;

By the way, all of that above hasn't been tested, but it should be pretty okay to use.

Let me know how you get on.

Regards,

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


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

PostPosted: Tue Jan 27, 2004 3:41 pm    Post subject: Reply with quote

Oh, I forgot to mention... Usually GD comes with PHP, but you may find you have to tweak your php.ini setting to use GD2x rather than GD1x.

If you're using Windows version of PHP, then compiled snapshots of various PECL libraries can be found at:

http://snaps.php.net/win32/PECL_STABLE/

Or you will be able to find the GD dll file in the Windows download of PHP from php.net.

If you're using the linux versions, then just download and recompile the code for GD (though you may have to install various other libraries, such as the jpeg libs, png libs, and so on).

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


Joined: 26 Jan 2004
Posts: 7

PostPosted: Tue Jan 27, 2004 4:04 pm    Post subject: Reply with quote

Andy,

When I load the package main menu, it sais GDBM1.8 is installed with it.

The pictures still won't load on screen, BUT ... when I past the directory used in the img tag directly into my browser ( http://localhost/php/includes/showimage.php?img=../../images/news_images/7.jpg&w=100&shadow=1&bgcolour=CCCCCC) I see the debug text saying the image is loaded together with the shadow ... The image however is not there, instead a lot of hex code can be seen (the image but in characters) ... Does this mean I haven't got GD installed.

Also, I found a GD homepage where I can download GD and its DLL. Should I just place the dir in my WIN system dir? (I'm using a WIN XP system here with apache, mysql and php) ...

Still, the little php file does not get loaded and my pictures are not there ... I'm really wondering what I'm doing wrong.

Maarten
Back to top
View user's profile Send private message
Maarten Martens
Newbie


Joined: 26 Jan 2004
Posts: 7

PostPosted: Tue Jan 27, 2004 4:05 pm    Post subject: Reply with quote

I found GD overhere
http://www.boutell.com/gd/

But their doc is extremely complex ...
Back to top
View user's profile Send private message
Maarten Martens
Newbie


Joined: 26 Jan 2004
Posts: 7

PostPosted: Tue Jan 27, 2004 4:12 pm    Post subject: Reply with quote

Andy,

I just got some info ... The GD 1 and GD2 dll files are there, and I have GD2 activated in the ini file ... So I guess I'm clear on that part ...

Greetz,
Maarten
Back to top
View user's profile Send private message
amnuts
Site Admin


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

PostPosted: Tue Jan 27, 2004 4:28 pm    Post subject: Reply with quote

Maarten Martens wrote:
The pictures still won't load on screen, BUT ... when I past the directory used in the img tag directly into my browser ( http://localhost/php/includes/showimage.php?img=../../images/news_images/7.jpg&w=100&shadow=1&bgcolour=CCCCCC) I see the debug text saying the image is loaded together with the shadow ... The image however is not there, instead a lot of hex code can be seen (the image but in characters) ... Does this mean I haven't got GD installed.


This is good.. All those funky characters are actually the image. However, they're displaying like that because text has already been output to the browser and so it cannot display the image as an image.

Set debugging to 'false' for the class and try directly calling the script again as you previously did... this is after you have added the 'header' line from my previous post. Did that display the image?

Great news about having GD2x already installed! Just make sure that the 1x version is commented out in the php.ini file so as not to confuse the two.

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


Joined: 26 Jan 2004
Posts: 7

PostPosted: Tue Jan 27, 2004 4:44 pm    Post subject: Reply with quote

Andy,

The image is not displayed ... just like the page I'm working on, only a red cross is displayed ... seems it can't find the image or something...

I'll test more ...

Maarten
Back to top
View user's profile Send private message
Maarten Martens
Newbie


Joined: 26 Jan 2004
Posts: 7

PostPosted: Tue Jan 27, 2004 4:44 pm    Post subject: Reply with quote

but it has to find the image, as it can show all the encrypted code ... there is something smelly here ... maybe GD is not properly installed after all?
Back to top
View user's profile Send private message
amnuts
Site Admin


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

PostPosted: Wed Jan 28, 2004 6:04 pm    Post subject: Reply with quote

Just to tie up this thread...

Turns out that the class.dropshadow.php file had some white-space at the end of the file. This had the effect of sending text/html content headers before the image was displayed which would account for the 'hex characters' being displayed (really it was the binary details of the file display as text/html).

Those darned spaces! Wink

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