C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Calculate New Height Based On New Width?

By : Santu
Date : October 15 2020, 11:12 PM
I wish this help you I have a control whose width is 500 and height is 240, and I want to maintain the aspect ratio. , Algebra tells us it should be:
code :

Share :

## Calculate text width based on available height?

By : user3152885
Date : March 29 2020, 07:55 AM
Hope this helps what you can do is to measure a string in a default size with this method: (g is a Graphics Object)
code :
``````g.MeasureString("area", Font, maxWidth)
``````
``````float measureFontSize = 5;
SizeF measuredBox = g.MeasureString("my string", new Font("Arial", measureFontSize));
double measuredProportion = measuredBox.Width / measuredBox.Height;

double expectedWidth = measuredProportion * wishedHeight;
``````

## How to calculate proportional width of an image based on its height?

By : SGRoeh
Date : March 29 2020, 07:55 AM
may help you . How to calculate proportional width of an image based on its height? , With known height and width:
code :
``````var ratio = image.Height / image.Width;
``````
``````var width = image.Height / ratio;
``````
``````var height = image.Width * ratio;
``````

## Calculate height of banner based on width

By : karan khanna
Date : March 29 2020, 07:55 AM
Any of those help It might be possible to do this with CSS alone. The problem with @media rules is that you'd need one for each pixel width, which isn't viable. So you could try this instead:
Firstly, change the wrapper div here:
code :
``````<div align="center">
``````
``````<div class="pluswrap">
``````
``````.pluswrap {
text-align: center;
height: 0;
position: relative;
}
``````

## Calculate the price based on height and width

By : Darshan Kale
Date : March 29 2020, 07:55 AM
will be helpful for those in need let's say that you want to do it on the product ID N° 1 from the product page : first add two inputs fields in your product.tpl ( or in your module.tpl called in product.tpl)
code :
``````<input name="height"><br>
<input name="width">
``````
``````\$id_product = 1;
\$newPrice = 0;
\$height = Tools::getValue('height');
\$width = Tools::getValue('width');

//Price rules (change with your rules)
if(\$height > 10 && \$width > 10) \$newPrice = 10;

\$specific_price = new SpecificPrice();
\$specific_price->price = \$newPrice;
\$specific_price->id_cart = (int) \$this->context->cart->id;
\$specific_price->id_shop = 0;
\$specific_price->id_shop_group = 0;
\$specific_price->id_currency = 0;
\$specific_price->id_country = 0;
\$specific_price->id_group = 0;
\$specific_price->id_customer = (int) \$this->context->customer->id;
\$specific_price->id_product = (int)\$id_product;
\$specific_price->id_product_attribute = 0;
\$specific_price->from_quantity = 1;
\$specific_price->reduction = 0;
\$specific_price->reduction_type = 'amount';
\$specific_price->from = '0000-00-00 00:00:00';
\$specific_price->to = '0000-00-00 00:00:00';
``````
``````    \$cart->id_lang = (int)(\$this->context->cookie->id_lang);
\$cart->updateQty(\$qte, \$id_product);
``````
``````class OrderConfirmationController extends OrderConfirmationControllerCore
{
public \$ssl = true;
public \$php_self = 'order-confirmation';
public \$id_cart;
public \$id_module;
public \$id_order;
public \$reference;
public \$secure_key;

public function getPriceBack(\$id_product){

\$normalPrice = Product::getPriceStatic(\$id_product);

\$specific_price = new SpecificPrice();
\$specific_price->price = \$normalPrice;
\$specific_price->id_cart = (int) \$this->context->cart->id;
\$specific_price->id_shop = 0;
\$specific_price->id_shop_group = 0;
\$specific_price->id_currency = 0;
\$specific_price->id_country = 0;
\$specific_price->id_group = 0;
\$specific_price->id_customer = (int) \$this->context->customer->id;
\$specific_price->id_product = (int)\$id_product;
\$specific_price->id_product_attribute = 0;
\$specific_price->from_quantity = 1;
\$specific_price->reduction = 0;
\$specific_price->reduction_type = 'amount';
\$specific_price->from = '0000-00-00 00:00:00';
\$specific_price->to = '0000-00-00 00:00:00';

}

public function init()
{
parent::init();

\$this->id_cart = (int)(Tools::getValue('id_cart', 0));
\$is_guest = false;

/* get normal price back */
\$id_product = 1;
self::getPriceBack(\$id_product);

/* check if the cart has been made by a Guest customer, for redirect link */
if (Cart::isGuestCartByCartId(\$this->id_cart)) {
\$is_guest = true;
} else {
}

\$this->id_module = (int)(Tools::getValue('id_module', 0));
\$this->id_order = Order::getOrderByCartId((int)(\$this->id_cart));
\$this->secure_key = Tools::getValue('key', false);
\$order = new Order((int)(\$this->id_order));
if (\$is_guest) {
\$customer = new Customer((int)\$order->id_customer);
}
if (!\$this->id_order || !\$this->id_module || !\$this->secure_key || empty(\$this->secure_key)) {
}
\$this->reference = \$order->reference;
if (!Validate::isLoadedObject(\$order) || \$order->id_customer != \$this->context->customer->id || \$this->secure_key != \$order->secure_key) {
}
\$module = Module::getInstanceById((int)(\$this->id_module));
if (\$order->module != \$module->name) {
}
}
}
``````
``````    \$this->context->cart->deleteProduct(1);

Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'specific_price WHERE  id_customer='.(int)\$this->context->customer->id);
``````

## Calculate height of div based off width & maintain proportion

By : E-l Pedro
Date : October 13 2020, 06:00 AM
seems to work fine Maintaining specific height:width ratios in CSS is usually done by exploiting the fact that padding percentage is always calculated based on the element's width.
For example, let's say you had an element with width: 500px, height: 300px and padding: 10%. Now you might expect the top and bottom paddings to be 10% of height, and the left and right paddings to be 10% of width. However this would give unequal vertical and horizontal paddings which is counter-intuitive to what is intended - equal paddings of 10%. To make sense of this we need to base the padding percentage on the save dimension, and that dimension has been chosen to be the width.
code :
``````width: 33%;
height: 0;
``````
``````footer {
max-width: 1000px;
margin: 0 auto;
background-color: rgba(0, 0, 0, 0.171);
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
footer div {
background-image: url('https://learnwebdesign.online/img/bg.jpg');
background-position: center;
background-size: cover;
background-repeat: no-repeat;
position: relative;
width: 33%;
height: 0;
}
footer div span {
/* Used as content wrapper, with flex to centre content */
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
background-color: rgba(165, 165, 165, 0.282);
``````<footer>