Connecting Tech Pros Worldwide Forums | Help | Site Map

Stop going past the decimal point

Familiar Sight
 
Join Date: Mar 2007
Posts: 146
#1: Jun 20 '09
I have an image script that resize images and it puts the image size into a database. But it's giving me results like: 100 x 43.75 - that's 100 wide and 43.75 high.

How can I make it just round off to the nearest one or would that mess the picture up when I use these sizes to display the picture?

Here's the part of the script that handles resizing:

Expand|Select|Wrap|Line Numbers
  1. list($b_width, $b_height) = getimagesize($file); // b_width and b_height = sizes of big picture.
  2.  
  3. $t_width = 100; // thumb no wider than 100px
  4. $t_height = 100; // thumb no higher than 100px
  5.  
  6. if($b_width > $b_height) { 
  7. $diff = $b_width / $t_width;
  8. $t_height = $b_height / $diff; 
  9. }
  10. elseif($b_height >= $b_width) { 
  11. $diff = $b_height / $t_height;
  12. $t_width = $b_width / $diff; 
  13. }
  14. $tn = imagecreatetruecolor($t_width, $t_height); 

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,938
#2: Jun 20 '09

re: Stop going past the decimal point


Check out round(), floor() and ceil().
Familiar Sight
 
Join Date: Mar 2007
Posts: 146
#3: Jun 21 '09

re: Stop going past the decimal point


Got it, thanks. Much of these functions aren't in my book.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,938
#4: Jun 21 '09

re: Stop going past the decimal point


Quote:

Originally Posted by DavidPr View Post

Got it, thanks. Much of these functions aren't in my book.

Just give php.net a search - it has all the functions ;)
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,748
#5: Jun 21 '09

re: Stop going past the decimal point


All hail php.net. It should never be more than two clicks away when your writing you PHP scripts!

If I were ever to get a tattoo (which I won't), that URL is what I would have written on me. (Next to the Firefox logo, of course.)
(A "chick-magnet", that would be! :D)
Reply