View Full Version : Thumbnails
AaronCampbell
10-04-2003, 12:01 PM
Ok, I'm trying to make thubnails out of regular photos, on the fly. I decided that this would be a good first step to learning how to build a REALLY nice photo gallery. Check out the php here: http://campbells.dikaios.net/pic.php
and the page that I call it from here: http://campbells.dikaios.net/test.php
It's not working. And the only thing I can think of is that either I made a big boo boo, be cause I don't know what I'm doing, OR, maybe there are different levels of php, and my host doesn't offer image manipulations?
Anyway, in the test.php page, there is a pic to the left that does not load. That is where the script is called.
n8thegreat
10-04-2003, 12:09 PM
php code?
AaronCampbell
10-04-2003, 12:34 PM
Yeah...Just rt click on the links, and choose save as. The links are:
http://campbells.dikaios.net/pic.php
http://campbells.dikaios.net/test.php
Rydberg
10-04-2003, 12:36 PM
PHP will always be parsed by the web server over HTTP, you must show us the code here on the forum in a message, attach it, or save it on your server as .phps or perhaps .txt.
AaronCampbell
10-04-2003, 12:55 PM
my bad...
Rydberg
10-04-2003, 01:02 PM
Well before I analyze your scripts any further, delete ALL text (XHTML) before and after the <?php ?> tags in pic.php. You should not send this information, since pic.php will not be an XHTML page, it will be treated as a JPEG and nothing else. Do not even put any white space before or after the PHP tags. This is one big fault with pic.php, and if this doesn't solve your problems, I'll look further.
Oh, and in general it would be better to use a variable in the query string. pic.php?file=blah.jpg. Just a bit more handy to be working with $_GET.
Hope it helps.
AaronCampbell
10-04-2003, 01:36 PM
Well, that made progress...now I get a black box that is 150px by 150px. So, at least it doesn't show as though the pic is missing. I'm gonna re-attach the 2 files, with the changes.
Rydberg
10-04-2003, 02:12 PM
Well it's working for me now...
There were some small things wrong, that PHP sent back NOTICEs for..
Change you constants declaration to this:
define('IMAGE_BASE', '/images');
define('MAX_WIDTH', 150);
define('MAX_HEIGHT', 150);
Other than that... Make sure you're using the right paths..
if the script is in the root, make sure your pics are in /images/ ..
Good luck
edit,
Oh and I forgot, there's a variable, $c2, being used that is not defined.. I used $c in those places.
AaronCampbell
10-04-2003, 02:49 PM
define('IMAGE_BASE', '/images');
define('MAX_WIDTH', 150);
define('MAX_HEIGHT', 150);
Thanks...that fixed it.
scoutt
10-05-2003, 12:26 AM
notices can be turned off and most host do that.
you don't really have to define anything and even if you do you don't have to define them that way. all this is FYI so take it as is.
actually notices are very annoying. it doesn't hurt the script if you don't define them.
Rydberg
10-05-2003, 04:13 AM
Notices make sure your code is correct. It might function anyway, but it's good practice to do what they say. I always make sure my scripts raise no errors or notices, and then I turn them off. Later, possible errors(db, file or image perhaps) will be handled by a custom error handling function. This will make your script look the same on all servers, no matter the configuration. It's pretty annoying having your complete layout destroyed, because PHP echoes a big fat NOTICE in the menu.
Displaying errors can be turned off completely in this script, with this command:
ini_set('display_errors', 0);
Or you alternatively use:
error_reporting(0);
which gives you more control of what errors to report. http://www.php.net/manual/en/function.error-reporting.php
Useful when you don't have access to the server configuration. .htaccess can also be used for this purpose if you're on Apache. The '@' that is already being used in pic.php is also handy, for suppressing errors on individual lines.
http://www.php.net/manual/en/language.operators.errorcontrol.php
It is generally recommended to have display_errors Off on production websites, but for debugging, keep them On. Notices as well.
I'm guessing that this script is something you've found on the net, and altered a bit. The way constants are defined and used here, is one way of doing things, and actually a pretty clean one.
http://www.php.net/manual/en/language.constants.php
:)
AaronCampbell
10-06-2003, 05:36 PM
One more thing for this script. I tried using it on a gif that has a transparent bg. Of course, the old version made all the files into a jpg, so I tried to change this. Having it use imagejpg($img) if the original was a jpg, imagepng($img) if the original was a png, and imagegif($img)if the original was a gif. it didn't work. The png and jpg work, but the gif did not, AND if I changed a gif into t a png, it loses it's transparency. Any ideas? I'll reattach the new files. It currently has imagepng($img)for png's AND gif's, since the gif one doesn't work at all.
AaronCampbell
10-06-2003, 05:40 PM
DOH!!
AaronCampbell
10-08-2003, 11:30 AM
Sorry to reply to my own posts in this thread (especially with nothing really NEW to add), but I'm still having problems with this, and I can't figure it out. I cannot seem to make this script output a gif, or anything with a clear background for that matter. I've searched, but can't find the answer. I can't really convert my site to use this, since I do have a gif or 2 with transparent bg's, and I relly want to keep them. Any ideas?
Rydberg
10-08-2003, 11:37 AM
imagegif()
Note: Since all GIF support was removed from the GD library in version 1.6, this function is not available if you are using that version of the GD library. Support is expected to return in a version subsequent to the rerelease of GIF support in the GD library in mid 2004. For more information, see the GD Project site.
http://www.php.net/manual/en/function.imagegif.php
mrmackey at fo-shizzle dot com
15-Jul-2003 03:04
In case you are wondering (I know I've been) GD support for GIFs will not re-appear until the patent GIF expires world-wide on July 7th, 2004. Though the patent has expired in the U.S. it hasn't in Europe.
AaronCampbell
10-08-2003, 12:35 PM
hmmm...bummer. Thanks though
scoutt
10-08-2003, 01:13 PM
why not make them png's and you will still be able to use the transparency. well somewhat, IE has problems with transparent png's.
look into
imagecolortransparent()
If you have a transparent PNG , in PHP 4.3.1 , GD 2.0 , you don't need to set the transparency anymore , it's automatic ...
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.