Welcome to WebmasterWorld Guest from 54.225.38.176

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Is it possible to create image thumbnails server-side?

Using PHP, either on the fly or on upload or ...?

     
3:02 pm on Mar 21, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 25, 2000
posts:663
votes: 0


I'm working on a site that will include multiple images, jpegs of undoubtedly large file size, and we'd like to offer up thumbnails first. Is there any way to create the thumbnails server-side? Either on-the-fly but I'm thinking that might put a large load on the server if we start getting lots of hits, or when the image file is uploaded, or, say, as a batch job once a week? The site is PHP/MySQL.
3:27 pm on Mar 21, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Here is a great reference for PHP [php.net] image [php.net] functions. There is a thumbnail creation example in the user notes.
4:25 pm on Mar 21, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 25, 2000
posts:663
votes: 0


Thanks for the rapid response, Birdman! Yes, I had found that referenc in the PHP manual. I'm a *relative* newbie to PHP scripting (I've put up half-a-dozen simple db based sites thus far). This site is on an outside host so I don't control the server. Is the "GD library" mentioned in the manual something that has to be pre-installed in the configuration on the server, or can I install it within my "account" on this host to get this to work?
4:51 pm on Mar 21, 2003 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


on the server, your host would have to set it up for you if it isn't already.

You could always try gd_info() [php.net] or phpinfo() [php.net]

4:58 pm on Mar 21, 2003 (gmt 0)

New User

10+ Year Member

joined:Mar 1, 2003
posts:19
votes: 0


louponne, if your hosting service doesn't have PH with GD installed, you cannot install install it yourself (unless you've admin access to the server).
the PHP functions using GD are very powerful and allow you to do lots of things once you manage to understand their use.
It's not always obvious at the begininning, but looking at the examples will help you.
I don't recommand you use on-the-fly image generation, especially with large files because it will put a high load on the server, and it is unnecessary to re-create thumbnails again all the time. Your jpeg files aren't going to change at every request!

I have a website with a photo album. After I've uploaded new pictures, I run a script that creates and saves to disk thumbnails for all new pictures. The same script is run once a day by night, in case I forgot to create some thumbnails.

Jocelyn

5:04 pm on Mar 21, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 28, 2002
posts:505
votes: 0


AFAIK the GD support has to be configured during PHP installation.
Just try a simple GD function -- if you get no error but a result, everything should work fine.
You may also try a <?php phpinfo();?> which will show you a long list of all features and parameters of the PHP on your server.
If you will find a '--with-gd=yes' in the 'Configure command' section, then you should be OK.

Regards,
R.

5:34 pm on Mar 21, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 25, 2000
posts:663
votes: 0


Thanks to all for your help thus far!
I just made a test.php with just gd_info(); in it and got
Fatal error: Call to undefined function: gd_info()...
So it looks like this host does not have this installed. :(
6:51 pm on Mar 21, 2003 (gmt 0)

New User

10+ Year Member

joined:Mar 1, 2003
posts:19
votes: 0


louponne, from the documentation of the gd_info() function, you can see that it only works with PHP 4.3.0 and better.
The error you got is a PHP error meaning that the function gd_info() is not defined. It doesn't tell whether GD is installed or not!
Run phpinfo(). It should work, and give you some info :
- PHP version
- if GD is installed or not
This is not as good as gd_info() but rather usefull anyway

Don't forget the documentation :
[php.net...]
[php.net...]
[php.net...]
[boutell.com...]

Jocelyn

8:03 pm on Mar 21, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 25, 2000
posts:663
votes: 0


oops - thanks for correcting me and many thanks for your patience with a relative newbie! Yes, I ran phpinfo() as you suggested. PHP 4.1.2 and gd is indeed "enabled". hurray. Now all I have to do is learn how to use it! Many thanks again for everyone's help!
10:50 pm on Mar 21, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


louponne,

I just posted a script in Bag-O-Tricks for PHP II [webmasterworld.com] that you may like to check out.

[edited by: coopster at 5:41 pm (utc) on Mar. 19, 2007]
[edit reason] fixed link [/edit]