473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Stop going past the decimal point

155 100+
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); 
Jun 20 '09 #1
4 1547
Markus
6,050 Expert 4TB
Check out round(), floor() and ceil().
Jun 20 '09 #2
DavidPr
155 100+
Got it, thanks. Much of these functions aren't in my book.
Jun 21 '09 #3
Markus
6,050 Expert 4TB
@DavidPr
Just give php.net a search - it has all the functions ;)
Jun 21 '09 #4
Atli
5,058 Expert 4TB
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)
Jun 21 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
7
by: hana1 | last post by:
Hello experts, I used to program in C/C++ and now switched to Java. I am having a difficulty that I need your help with. How can I limit a double variable to hold 2 decimal points only? Say I...
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
8
by: Matt Theule | last post by:
While stepping through an ASP.NET project, I found that data was being inserted into my database even though I was not stepping through the code that inserted the data. I have a single page with...
18
by: Kuljit | last post by:
I am doing Engineering(B.Tech) in Computer Science. I have a question for which i am struggling to write a C code(program). It struck me when we were being taught about a program which counts the...
11
by: Pieter | last post by:
Hi, I'm having some troubles with my numeric-types in my VB.NET 2005 application, together with a SQL Server 2000. - I first used Single in my application, and Decimal in my database. But a...
56
by: valentin tihomirov | last post by:
{ int i = 2; } int i = 1; There is no 'i' defined in the 'parent' context from the moment of declaration on. So what is the problem? They tell us they pursue language simplicity. The rule "do...
16
by: jimmy.musselwhite | last post by:
Hello all It would be great if I could make a number that can go beyond current size limitations. Is there any sort of external library that can have infinitely huge numbers? Way way way way...
8
by: Lemune | last post by:
Hi, I'm developing window service application on C# 2005. The service is to read a new excel file on certain directory, and process it to database. The service work find on XP. But when I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.