473,732 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_widt h_and_height(&$ width, &$height, $origWidth,
$origHeight) {
print_r("width = $width and origWidth = $origWidth and height =
$height and origHeight = $origHeight<P>" );
if ((int)$origWidt h === 0 || (int)$origHeigh t === 0) return array();
// TO AVOID DIVISION BY ZERO
if ((int)$origWidt h !== (int)$width && (int)$origHeigh t !==
(int)$height) return array($width, $height); // NO NEED TO CALCULATE
SINCE CHANGING ALL DIMENSIONS
if ((int)$origWidt h !== (int)$width) $height = $height / ($width /
$origWidth);
if ((int)$origHeig ht !== (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 3888
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_widt h_and_height(&$ width, &$height, $origWidth,
$origHeight) {
if ((int)$origWidt h === 0 || (int)$origHeigh t === 0) return
array($width, $height); // TO AVOID DIVISION BY ZERO
if ((int)$origWidt h !== (int)$width && (int)$origHeigh t !==
(int)$height) return array($width, $height); // NO NEED TO CALCULATE
SINCE CHANGING ALL DIMENSIONS
if ((int)$origWidt h !== (int)$width) $height = $width * ($origHeight
/ $origWidth);
if ((int)$origHeig ht !== (int)$height) $width = $height * ($origWidth
/ $origHeight);
return array(floor($wi dth), 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
4171
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 why it doesn't work? Thanks in advance Tjerk
9
2047
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 one. Maybe I am just getting blurry-eyed, but can someone help me figure out what I have done wrong? Thanks!!!! <td width="190" height="57"><a href="Trends.htm" onmouseover="chgImg('Trends','InteriorTrendsBold')"...
5
2147
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 of pic.jpg is (had I not placed the height and width attributes on the image, whether in the original tag or later via javascript)?
15
31807
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 help. Regards
6
24190
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 mouseout are working perfect but only the source is not setting using java script. Please clarify me regarding this. PS: This problem is only for safari browser. <tr>
4
2754
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. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
1
2034
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 and after displayed it.plz tell that how to start the logic. <?php // Connect to database $errmsg = "";if (! @mysql_connect("localhost","root","sreeni")) { $errmsg = "Cannot connect to database"; } @mysql_select_db("my_db1");...
3
4430
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 when iam using a normal web page... but can't in content page.... Code in Master Page <%@ Master Language="C#" AutoEventWireup="true" CodeFile="submaster.master.cs" Inherits="submaster" %> <%@ Register Assembly="AjaxControlToolkit"...
2
4094
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 but cant seem to find out what the problem is. I think this could be fixed with a i.e hack??? please advise the problem of the overlapping image is occuring in imagerow2 div on line 56. please see my code below here is my html <!DOCTYPE...
0
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9445
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9234
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.