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: <!-- m --><a class="postlink" href="http://campbells.dikaios.net/pic.php">http://campbells.dikaios.net/pic.php</a><!-- m -->
and the page that I call it from here: <!-- m --><a class="postlink" href="http://campbells.dikaios.net/test.php">http://campbells.dikaios.net/test.php</a><!-- m -->
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.php code?Yeah...Just rt click on the links, and choose save as. The links are:
<!-- m --><a class="postlink" href="http://campbells.dikaios.net/pic.php">http://campbells.dikaios.net/pic.php</a><!-- m -->
<!-- m --><a class="postlink" href="http://campbells.dikaios.net/test.phpPHP">http://campbells.dikaios.net/test.phpPHP</a><!-- m --> 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.my bad...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.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.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.define('IMAGE_BASE', '/images');
define('MAX_WIDTH', 150);
define('MAX_HEIGHT', 150);
Thanks...that fixed it.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.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. <!-- m --><a class="postlink" href="http://www.php.net/manual/en/function.error-reporting.php">http://www.php.net/manual/en/function.e ... orting.php</a><!-- m -->
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.
<!-- m --><a class="postlink" href="http://www.php.net/manual/en/language.operators.errorcontrol.php">http://www.php.net/manual/en/language.o ... ontrol.php</a><!-- m -->
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.
<!-- m --><a class="postlink" href="http://www.php.net/manual/en/language.constants.php">http://www.php.net/manual/en/language.constants.php</a><!-- m -->
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.DOH!!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?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.
<!-- m --><a class="postlink" href="http://www.php.net/manual/en/function.imagegif.php">http://www.php.net/manual/en/function.imagegif.php</a><!-- m -->
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.hmmm...bummer. Thanks thoughwhy 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 ...
and the page that I call it from here: <!-- m --><a class="postlink" href="http://campbells.dikaios.net/test.php">http://campbells.dikaios.net/test.php</a><!-- m -->
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.php code?Yeah...Just rt click on the links, and choose save as. The links are:
<!-- m --><a class="postlink" href="http://campbells.dikaios.net/pic.php">http://campbells.dikaios.net/pic.php</a><!-- m -->
<!-- m --><a class="postlink" href="http://campbells.dikaios.net/test.phpPHP">http://campbells.dikaios.net/test.phpPHP</a><!-- m --> 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.my bad...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.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.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.define('IMAGE_BASE', '/images');
define('MAX_WIDTH', 150);
define('MAX_HEIGHT', 150);
Thanks...that fixed it.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.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. <!-- m --><a class="postlink" href="http://www.php.net/manual/en/function.error-reporting.php">http://www.php.net/manual/en/function.e ... orting.php</a><!-- m -->
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.
<!-- m --><a class="postlink" href="http://www.php.net/manual/en/language.operators.errorcontrol.php">http://www.php.net/manual/en/language.o ... ontrol.php</a><!-- m -->
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.
<!-- m --><a class="postlink" href="http://www.php.net/manual/en/language.constants.php">http://www.php.net/manual/en/language.constants.php</a><!-- m -->
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.DOH!!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?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.
<!-- m --><a class="postlink" href="http://www.php.net/manual/en/function.imagegif.php">http://www.php.net/manual/en/function.imagegif.php</a><!-- m -->
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.hmmm...bummer. Thanks thoughwhy 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 ...