note 99215 added to function.imagecolortransparent

From: Date: Wed, 04 Aug 2010 08:33:13 +0000
Subject: note 99215 added to function.imagecolortransparent
Groups: php.notes 
Request: Send a blank email to php-notes+get-171368@lists.php.net to get a copy of this message
as posted before, the below function createThumb still has a problem with correct scaling. when creating thumbnails, the new width and new height represent the maximum width and height the thumbnail should have. consider the following <?php $old_w = 200; $old_h = 100; $new_w = 200; $new_h = 50; /* original code from createThumb */ if($old_w < $new_w && $old_h < $new_h) { $thumb_w = $old_w; $thumb_h = $old_h; } elseif ($old_w > $old_h) { $thumb_w = $new_w; $thumb_h = floor(($old_h*($new_h/$old_w))); } elseif ($old_w < $old_h) { $thumb_w = floor($old_w*($new_w/$old_h)); $thumb_h = $new_h; } elseif ($old_w == $old_h) { $thumb_w = $new_w; $thumb_h = $new_h; } var_dump($thumb_w, $thumb_h); /* output: int 200 float 25 */ ?> the thumbnail will be 200x25, instead of 100x50. a correct way to do it: <?php $w_f = $new_w/$old_w; // factor for scaling per width $h_f = $new_h/$old_h; // factor for scaling per height if ($w_f >= $w_h) // scale per height { $thumb_w = $old_w * $h_f; $thumb_h = $new_h; } else// scale per width { $thumb_w = $new_w; $thumb_h = $old_h * $w_f; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 85.183.47.159 ---- Manual Page -- http://www.php.net/manual/en/function.imagecolortransparent.php Edit -- https://master.php.net/note/edit/99215 Del: integrated -- https://master.php.net/note/delete/99215/integrated Del: useless -- https://master.php.net/note/delete/99215/useless Del: bad code -- https://master.php.net/note/delete/99215/bad+code Del: spam -- https://master.php.net/note/delete/99215/spam Del: non-english -- https://master.php.net/note/delete/99215/non-english Del: in docs -- https://master.php.net/note/delete/99215/in+docs Del: other reasons-- https://master.php.net/note/delete/99215 Reject -- https://master.php.net/note/reject/99215 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171368) next »