note 36452 added to function.getimagesize

From: Date: Thu, 09 Oct 2003 19:19:54 +0000
Subject: note 36452 added to function.getimagesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-58170@lists.php.net to get a copy of this message
If you want to show thumbnails keeping the original proportions, with defined maximum width and height, you can use this function. This is useful when showing tables of user-uploaded images, that not necessarily are same-sized. However, for big images (like wallpapers), a better option is to create separated thumbnails with a image-editing software. If the image is smaller or equal than the defined maximums, then it's showed without resizing. If not, creates a link to a pop-up that shows the full-size image. <?php function show_thumbnail($file) { $max = 200 // Max. thumbnail width and height $size = getimagesize($file); if ( $size[0] <= $max && $size[1] <= $max ) { $ret = '<img src="'.$file.'" '.$size[3].' border="0">'; } else { $k = ( $size[0] >= $size[1] ) ? $size[0] / $max : $size[1] / $max; $ret = '<a href="javascript:;" onClick="window.open(\'image.php?img='; $ret .= $file.'\',\'\',\'width='.$size[0]; $ret .= ',height='.$size[1].'\')">'; $ret .= '<img src="'.$file.'" width="'.floor($size[0]/$k).'" height="'.floor($size[1]/$k).'" border="0" alt="View full-size image"></a>'; } return $ret; } ?> Here is the code of 'image.php': <html> <head> <title>Image</title> </head> <body leftmargin="0" topmargin="0"> <?php echo ( is_file($_GET['img']) ) ? '<a href="#" onClick="window.close();"><img src="'.$_GET['img'].'" border="0" alt="Close window"></a>' : 'Invalid image filename, or no filename entered. <a href="#" onClick="window.close();">Close window</a>.' ?> </body> </html> ---- Manual Page -- http://www.php.net/manual/en/function.getimagesize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36452 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36452&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36452&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58170) next »