note 95876 added to function.getimagesize

From: Date: Tue, 26 Jan 2010 23:26:52 +0000
Subject: note 95876 added to function.getimagesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-165346@lists.php.net to get a copy of this message
This should be easy, but I've re-solved the problem so many times. Hopefully this is useful - if there are any logic errors, let me know: // Usage example to find the proper dimensions to resize an image down to 300x400 pixels maximum: list($width, $height) = getimagesize($image); $new_dimensions = resize_dimensions(300,400,$width,$height); // Calculates restricted dimensions with a maximum of $goal_width by $goal_height function resize_dimensions($goal_width,$goal_height,$width,$height) { $return = array('width' => $width, 'height' => $height); // If the ratio > goal ratio and the width > goal width resize down to goal width if ($width/$height > $goal_width/$goal_height && $width > $goal_width) { $return['width'] = $goal_width; $return['height'] = $goal_width/$width * $height; } // Otherwise, if the height > goal, resize down to goal height else if ($height > $goal_height) { $return['width'] = $goal_height/$height * $width; $return['height'] = $goal_height; } return $return; } ---- Server IP: 69.147.83.197 Probable Submitter: 128.223.105.110 ---- Manual Page -- http://www.php.net/manual/en/function.getimagesize.php Edit -- https://master.php.net/note/edit/95876 Del: integrated -- https://master.php.net/note/delete/95876/integrated Del: useless -- https://master.php.net/note/delete/95876/useless Del: bad code -- https://master.php.net/note/delete/95876/bad+code Del: spam -- https://master.php.net/note/delete/95876/spam Del: non-english -- https://master.php.net/note/delete/95876/non-english Del: in docs -- https://master.php.net/note/delete/95876/in+docs Del: other reasons-- https://master.php.net/note/delete/95876 Reject -- https://master.php.net/note/reject/95876 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165346) next »