手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:imageworkshop

imageworkshop中的position的说明及代码

position有9个点:lt,mt,rt,lm,mm,rm,lb,mb,rb,其实对应的是几个英文:lt(left top),mt(middle top),rt(right top),以此类推

上官方原图:

大小: 49.72 K
尺寸: 376 x 376
浏览: 1692 次
点击打开新窗口浏览全图

OK,然后我们看一下他的代码是怎么写的,如果有人涉及到也可以借鉴:

 

PHP代码
  1. <?php  
  2.   
  3. /** 
  4.      * Calculate the left top positions of a layer inside a parent layer container 
  5.      * $position: http://phpimageworkshop.com/doc/22/corners-positions-schema-of-an-image.html 
  6.      * 
  7.      * @param integer $containerWidth 
  8.      * @param integer $containerHeight 
  9.      * @param integer $layerWidth 
  10.      * @param integer $layerHeight 
  11.      * @param integer $layerPositionX 
  12.      * @param integer $layerPositionY 
  13.      * @param string $position 
  14.      * 
  15.      * @return array 
  16.      */  
  17.     public static function calculatePositions($containerWidth$containerHeight$layerWidth$layerHeight$layerPositionX$layerPositionY$position = 'LT')  
  18.     {  
  19.         $position = strtolower($position);  
  20.   
  21.         if ($position == 'rt') {  
  22.   
  23.             $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;  
  24.   
  25.         } elseif ($position == 'lb') {  
  26.   
  27.             $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;  
  28.   
  29.         } elseif ($position == 'rb') {  
  30.   
  31.             $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;  
  32.             $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;  
  33.   
  34.         } elseif ($position == 'mm') {  
  35.   
  36.             $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;  
  37.             $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;  
  38.   
  39.         } elseif ($position == 'mt') {  
  40.   
  41.             $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;  
  42.   
  43.         } elseif ($position == 'mb') {  
  44.   
  45.             $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;  
  46.             $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;  
  47.   
  48.         } elseif ($position == 'lm') {  
  49.   
  50.             $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;  
  51.   
  52.         } elseif ($position == 'rm') {  
  53.   
  54.             $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;  
  55.             $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;  
  56.         }  
  57.   
  58.         return array(  
  59.             'x' => $layerPositionX,  
  60.             'y' => $layerPositionY,  
  61.         );  
  62.     }  

END;

 

 

 

Tags: imageworkshop, position