note 42970 modified in function.getimagesize by tularis

From: Date: Wed, 04 Aug 2004 21:42:34 +0000
Subject: note 42970 modified in function.getimagesize by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73959@lists.php.net to get a copy of this message
--- Editor's Note: It's easier to call on urlencode() or rawurlencode() to "fix" urls containing spaces and other characters that normally not well-liked. --- You may have noticed that images with spaces WONT work with getimagesize - some of us have massive amounts of pictures, or don't feel like rewriting file names on users uploaded pictures- so here is a super fast fix that will replace the spaces once the image is called and will work with getimagesize flawlessly- $image_new = "/pictures/$pic[picture]"; //PICTURE URL $image_new = str_replace(' ','%20',$image_new); //REPLACE THE SPACES Now you just call $image_new using getimagesize and you wont' have anymore problems. On my site I take uploaded pictures from users - then resize them if they are over a certain width, here is the script i use if anyone would like to do this- $image_new = "/pictures/$pic[picture]"; //url of picture $image_new = str_replace(' ','%20',$image_new); //take url and replace spaces $max_width= "480"; //maximum width allowed for pictures $resize_width= "480"; //same as max width $size = getimagesize("$image_new"); //get the actual size of the picture $width= $size[0]; // get width of picture $height= $size[1]; // get height of picture if ($width>$max_width){ $new_width=$resize_width; // Resize Image If over max width }else { $new_width=$width; // Keep original size from array because smaller than max } echo "<IMG src=\"$image_new\" border=1 width=$new_width>" //print image with new width Hope this helps anyone who wants some simple uses for getimagesize- check out my website to see it in action- vitalmodels.com --was-- You may have noticed that images with spaces WONT work with getimagesize - some of us have massive amounts of pictures, or don't feel like rewriting file names on users uploaded pictures- so here is a super fast fix that will replace the spaces once the image is called and will work with getimagesize flawlessly- $image_new = "/pictures/$pic[picture]"; //PICTURE URL $image_new = str_replace(' ','%20',$image_new); //REPLACE THE SPACES Now you just call $image_new using getimagesize and you wont' have anymore problems. On my site I take uploaded pictures from users - then resize them if they are over a certain width, here is the script i use if anyone would like to do this- $image_new = "/pictures/$pic[picture]"; //url of picture $image_new = str_replace(' ','%20',$image_new); //take url and replace spaces $max_width= "480"; //maximum width allowed for pictures $resize_width= "480"; //same as max width $size = getimagesize("$image_new"); //get the actual size of the picture $width= $size[0]; // get width of picture $height= $size[1]; // get height of picture if ($width>$max_width){ $new_width=$resize_width; // Resize Image If over max width }else { $new_width=$width; // Keep original size from array because smaller than max } echo "<IMG src=\"$image_new\" border=1 width=$new_width>" //print image with new width Hope this helps anyone who wants some simple uses for getimagesize- check out my website to see it in action- vitalmodels.com http://php.net/manual/en/function.getimagesize.php

« previous php.notes (#73959) next »