position有9个点:lt,mt,rt,lm,mm,rm,lb,mb,rb,其实对应的是几个英文:lt(left top),mt(middle top),rt(right top),以此类推
上官方原图:
OK,然后我们看一下他的代码是怎么写的,如果有人涉及到也可以借鉴:
PHP代码
- <?php
 - /**
 - * Calculate the left top positions of a layer inside a parent layer container
 - * $position: http://phpimageworkshop.com/doc/22/corners-positions-schema-of-an-image.html
 - *
 - * @param integer $containerWidth
 - * @param integer $containerHeight
 - * @param integer $layerWidth
 - * @param integer $layerHeight
 - * @param integer $layerPositionX
 - * @param integer $layerPositionY
 - * @param string $position
 - *
 - * @return array
 - */
 - public static function calculatePositions($containerWidth, $containerHeight, $layerWidth, $layerHeight, $layerPositionX, $layerPositionY, $position = 'LT')
 - {
 - $position = strtolower($position);
 - if ($position == 'rt') {
 - $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
 - } elseif ($position == 'lb') {
 - $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
 - } elseif ($position == 'rb') {
 - $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
 - $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
 - } elseif ($position == 'mm') {
 - $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
 - $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
 - } elseif ($position == 'mt') {
 - $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
 - } elseif ($position == 'mb') {
 - $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
 - $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
 - } elseif ($position == 'lm') {
 - $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
 - } elseif ($position == 'rm') {
 - $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
 - $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
 - }
 - return array(
 - 'x' => $layerPositionX,
 - 'y' => $layerPositionY,
 - );
 - }
 
END;

