onion2k wrote:
2. When you use getimagesize() you should always wrap it in a block that checks the image exists using file_exists(). Never assume a file exists even if you're sure it always will.
This is always a good point and a good programming procedure "validating the information or resource you are going to work to. Because of that I use to use these two functions
Code: Select all
############################################### IS IMAGE? file exists?
function is_image($string){
// check if file exists and if at the end of the string there is an image extension
return ((file_exists("$string"))&&(preg_match('#(\.jpg|\.jpeg|\.gif|\.png|\.bmp)$#i',$string))) ? true : false ;
}
############################################### return an alternative when the given one is missing
function image_exists($string,$default){
// $string is the image you are passing, default is the alternative image string
return (is_image($string)) ? ("$string") : ("$default");
}
/*
So you coud use:
$my_image = image_exists("images/image1.jpg","images/default.jpg";
$imageXY = getimagesize($my_image);
*/
Of course the image control is just "filename based" so it doesn't check if it's really an image file, you could be less permissive if you need. (permissive??? is it correct in english?)
onion2k wrote:
1. There's a lovely thumbnail class that maintains proportions on
http://www.phpgd.com ... There's ones that do fancy stuff like rounding corners and drop shadows too.
Hummm could be a nice point to discuss!!! Of course if you are on a productive team or need to resolve something in a quick efficient way your point would be perfect form me, meaning "don't create the hot water again if someone does it before an better" but..... I think that you can only become an excellent programmer (if you can of course; I think it'll takes me 2 or 3 lives to be there....may be more

) is writing your own code and use the foreign scripts just for inspiration or understanding procedure and logic, the human being learns only when he/she needs to find a solution, to adapt. And of course creating your own code is the only way to have the solutions that fits with your problem (not more, not less). It's not good to use a Jedi laser sword to cut your nails when you can use scissors (may be this is not the case because the script you show us is very beautyfull and fast). Anytime I can I take advantages of creating the hot water again just to see what comes out, sometimes creating the hot water you have the answer for something else unexpected.