PHP calculate percent that an image resolution has over another's image resolution
I would like to know how can I tell what percent does one image's resolution represents from another image's resolution. So I have $resolution1 = '480x210' and $resolution2 = '720x480' . I want to find out how much $resolution1 represents, in percentage, from $resolution2. I am trying to make a business card print preview and want to show the client how small is his uploaded image in comparison with the needed size. So I got a blank proper sized div and I will render a thumbnail of the uploaded image in it but the thumbnail is made at X% 开发者_运维技巧its size (this is what I need to know) so that I can represent how much space on the card would his image take.
I am using PHP and imagemagick binaries with exec(). Any ideas ?
Thanks.
Soimething like this should work, if not it will help you get closer to your goal:
//Get the x / y of both resolutions
list($ax,$ay) = explode("x",'480x210');
list($bx,$by) = explode("x",'720x480');
//Get the difference of both resolutions
$calc_x = ($ax / $ay);
$calc_y = ($bx / $by);
//Calculate the increase
$increase = ($calc_x / $calc_y) * 100;
im not the best with maths but i think this is how you calculate the increase, the result of the above is 152.38095238095
which is 152.38%
increase
$resolution1width / $resolution2width = $returnwidthpercent;
$resolution1height / $resolution2height = $returnhieghtpercent;
div width = rendered image width + (rendered image width * $returnwidthpercent);
and the same for height. I think that should work.
精彩评论