473,320 Members | 1,977 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.

calculate image height or width

Sorry folks, I'm on a roll!!!

I need to calculate the height or width of an image if you change
either the width or height and don't change BOTH of them at the same
time, this is to "vector" the image.

Here is the class method, it obviously doesn't work:

[PHP]
/**
* Perform calculation solely upon re-entered width and height if a
calculation percentage was not entered nor chosen. Can be called
statically
*
* @access protected
* @param int $width (reference)
* @param int $height (reference)
* @param int $origWidth
* @param int $origHeight
* @return array $dimArray Array consisting of recalculated width and
height
*/
function &calculate_width_and_height(&$width, &$height, $origWidth,
$origHeight) {
print_r("width = $width and origWidth = $origWidth and height =
$height and origHeight = $origHeight<P>");
if ((int)$origWidth === 0 || (int)$origHeight === 0) return array();
// TO AVOID DIVISION BY ZERO
if ((int)$origWidth !== (int)$width && (int)$origHeight !==
(int)$height) return array($width, $height); // NO NEED TO CALCULATE
SINCE CHANGING ALL DIMENSIONS
if ((int)$origWidth !== (int)$width) $height = $height / ($width /
$origWidth);
if ((int)$origHeight !== (int)$height) $width = $width / ($height /
$origHeight);
print_r("width = $width and origWidth = $origWidth and height =
$height and origHeight = $origHeight<P>");
return array($width, $height);
}
[/PHP]

Ok, folks, what on earth do I do? The calculations are horrifically
wrong. How do I fix this? The values of $width and $height are entered
via FORM posts.

Phil

Apr 10 '06 #1
1 3865
Never mind, I got it on my own:

/**
* Perform calculation solely upon re-entered width and height if a
calculation percentage was not entered nor chosen. Can be called
statically
*
* @access protected
* @param int $width (reference)
* @param int $height (reference)
* @param int $origWidth
* @param int $origHeight
* @return array $dimArray Array consisting of recalculated width and
height
*/
function &calculate_width_and_height(&$width, &$height, $origWidth,
$origHeight) {
if ((int)$origWidth === 0 || (int)$origHeight === 0) return
array($width, $height); // TO AVOID DIVISION BY ZERO
if ((int)$origWidth !== (int)$width && (int)$origHeight !==
(int)$height) return array($width, $height); // NO NEED TO CALCULATE
SINCE CHANGING ALL DIMENSIONS
if ((int)$origWidth !== (int)$width) $height = $width * ($origHeight
/ $origWidth);
if ((int)$origHeight !== (int)$height) $width = $height * ($origWidth
/ $origHeight);
return array(floor($width), floor($height));
}

Phil

Apr 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tjerk | last post by:
Hello all, I have the script below to change an image depending on the date upto january it worked fine but then it just stopped working does anybody have an idea how I can make it work again or...
9
by: Karl Burrows | last post by:
I am working on a Website for a non-profit group and for some reason I have one link that doesn't want to cooperate. All the image links work fine with the onmouseover and onmouseout script except...
5
by: Csaba Gabor | last post by:
Is there any way to determine the pixel height and width of an original image? Specifically, If I have <IMG id=myImg src="pic.jpg" height=200 width=300> can I figure out what the original size...
15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
6
by: abdullah1983 | last post by:
Hi Guys, I need some clarification regarding the problem with safari browser. Please find my code below. I'm setting the image src, mouseover and mouseout using javascript. The mouseover and...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
1
by: sravani1 | last post by:
This code runs like when i submit the form it takes the image and displayed and top of the image a map will displayed. But actually i want that when i give the image it checks the location in the map...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
2
by: studentofknowledge | last post by:
For some unknown reason ie is placing images I have in a div in a weird way. One image is overlapping another but this problem is not occuring in mozilla. I have looked at my code over and over again...
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.