note 42970 added to function.getimagesize

From: Date: Sat, 05 Jun 2004 05:06:11 +0000
Subject: note 42970 added to function.getimagesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-70713@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.getimagesize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42970 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42970&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42970&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#70713) next »