Connecting Tech Pros Worldwide Help | Site Map

Stop going past the decimal point

  #1  
Old June 20th, 2009, 10:45 PM
Familiar Sight
 
Join Date: Mar 2007
Posts: 146
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); 
  #2  
Old June 20th, 2009, 11:02 PM
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,862
Provided Answers: 9

re: Stop going past the decimal point


Check out round(), floor() and ceil().
  #3  
Old June 21st, 2009, 02:08 AM
Familiar Sight
 
Join Date: Mar 2007
Posts: 146

re: Stop going past the decimal point


Got it, thanks. Much of these functions aren't in my book.
  #4  
Old June 21st, 2009, 08:21 AM
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,862
Provided Answers: 9

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 ;)
  #5  
Old June 21st, 2009, 03:27 PM
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,701
Provided Answers: 4

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 14th, 2005 04:15 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 11:37 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 09:56 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 03:15 AM