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

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
浏览: 2413 次
点击打开新窗口浏览全图

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

access-control-allow-origin-multiple-origin-domains

原文来自:http://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains

主要是因为涉及到CSS和JS文件是挂在别的域,然后又遇到了ajax之类的操作,所以就需要有跨域操作了,本来很方便的,只是在.htaccess文件中加了一句
XML/HTML代码
  1. Header add Access-Control-Allow-Origin "http://xxxxxx.com"  
但因为备案原因,所以又添加了一个备用域名,结果,就报错了,报错提示是:
XML/HTML代码
  1. font from origin 'http://xxxxx.com' has been blocked from loading by Cross-Origin Resource Sharing policy: The 'Access-Control-Allow-Origin' header contains multiple values 'http://yyyy.com, http://zzzz.com', but only one is allowed. Origin 'http://xxxxx.com' is therefore not allowed access.  
我晶,不支持多域名啊,google了一下,找到了这一篇:http://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains
 
不多贴,其实挺有意思。。方法也有不少
1、利用apache的环境变量:
XML/HTML代码
  1. SetEnvIf Origin "^(.*\.example\.com)$" ORIGIN_SUB_DOMAIN=$1  
  2. <FilesMatch "\.woff$">  
  3.     Header set Access-Control-Allow-Origin "%{ORIGIN_SUB_DOMAIN}e" env=ORIGIN_SUB_DOMAIN  
  4. </FilesMatch>  
2、用PHP来判断:
PHP代码
  1. $http_origin = $_SERVER['HTTP_ORIGIN'];  
  2.   
  3. if ($http_origin == "http://www.domain1.com" || $http_origin == "http://www.domain2.com" || $http_origin == "http://www.domain3.info")  
  4. {    
  5.     header("Access-Control-Allow-Origin: $http_origin");  
  6. }  
3、和1有点类似
XML/HTML代码
  1. SetEnvIf Origin "^http(s)?://(.+\.)?(domain\.org|domain2\.com)$" origin_is=$0   
  2. Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is  
4、这是nginx的:
XML/HTML代码
  1. location /fonts {  
  2.     # this will echo back the origin header  
  3.     if ($http_origin ~ "example.org$") {  
  4.         add_header "Access-Control-Allow-Origin" $http_origin;  
  5.     }  
  6. }  
更多的,还是去原网页看吧。。

利用pubu.im来做BUG提醒工具

BUG提醒工具其实有很多,比如可以在有BUG的时候发封邮件到你的常用邮箱,这样你的手机上(邮件APP)就会收到一条提醒。或者有短信SP通道的话,你也可以有类似处理。当然还有monolog,支持php-console插件,可以发送到你的chrome上面,我在这里再换个小方式,利用pubu.im这个IM工具(或者说。。。。说不出来)来做提醒

流程很简单

1、去pubu.im测试一个帐户。。这不用我多说吧

2、下载MAC客户端登录,自己添加自己为一个机器人,相当于自己和自己聊天,如果你的消息不算隐私,你可以直接用现成的:小布 这个通道

3、在聊天界面选择插件,点击更多,打开网页,添加“incoming”插件,生成一个URL,选择你刚才聊天组

4、根据提示信息在你的APP里写上一段测试代码,POST方式的,可以用curl/file_get_contents/Requests/guzzle等,工具实在太多,不想多说

5、测试通过后,可以尝试自己用set_error_handle,自己处理出错信息,在出错信息前进行判断:

if(debug_mode){ //send report }

6、你会发现 右上角弹了一个小窗,就是你刚才的测试标题!

----EOF---

就这样,你在工作的时候不需要打开手机,电脑上会直接有提醒哦~~~而且因为是聊天记录,你还可以往前翻,到底是什么BUG,嗯,再也不用客户端开发人员和你说,XXX接口出错了。。。因为他一出错你就收到,然后你就可以在他没有和你提的时候悄悄的改掉,等他提出来有BUG的时候,你说,在哪里?一定是你访问的姿势不对,不信你试试

哈哈

Tags: bug

aliyun的dotdeb源有BUG

纯笔记做个记录
1、http://mirrors.aliyun.com/ ,这是阿里的源

2、这是dotdeb的说明:http://mirrors.aliyun.com/help/dotdeb

3、阿里云的说明:

XML/HTML代码
  1. 编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最后面添加以下条目(操作前请做好相应备份)  
  2.   
  3. deb http://mirrors.aliyun.com/dotdeb/packages.dotdeb.org wheezy all  
  4. deb-src http://mirrors.aliyun.com/dotdeb/packages.dotdeb.org wheezy all  

其实上面的源的写法是错误的,不需要package.dotdeb.org,应该是这样

XML/HTML代码
  1.   
  2. deb http://mirrors.aliyun.com/dotdeb wheezy all  
  3. deb-src http://mirrors.aliyun.com/dotdeb wheezy all  

不过,如果是默认这样其实没有什么特别用,PHP还是5.4,所以如果要针对PHP,就需要再加上

XML/HTML代码
  1. deb http://mirrors.aliyun.com/dotdeb wheezy-php56 all    
  2. deb-src http://mirrors.aliyun.com/dotdeb wheezy-php56 all    

其实说白了就是看:http://mirrors.aliyun.com/dotdeb/dists/,看这一页支持哪些,然后加在源里就OK了。就象官网说的,如果是阿里云服务器,请使用aliyuncs,流量直接从内网走~

 

 

curl上传注意事项【新】

 众所周知,用curl上传只要设置4个变量即可(非HTTPS网站),那就是curlopt_url,curlopt_post,curlopt_returntransfer,curlopt_postfields,当然这4个都是大写。

curlopt_post,curlopt_returntransfer 都是 true,curlopt_url则是你要提交的网址,那么剩下的,curlopt_postfields就是你要上传的内容了。

上传文件在这里也变得非常简单,只需对应的值前面加个“@”即可,如curl_setopt($ch,CURLOPT_POSTFIELDS,array('file'=>'@/var/www/images/abc.jpg')); 文件通过realpath判断后存在的即可。

但是,这一切在php5.6里就发生了改成。php5.6不再支持@这样的上传方式,只能使用curl_file_create的方式来,所以上面的代码要改成

PHP代码
  1. curl_setopt($ch,CURLOPT_POSTFIELDS,array('file'=>curl_file_create('/var/www/images/abc.jpg','image/jpg','abc')));   

 

看看文档里怎么说:

XML/HTML代码
  1. CURLFile should be used to upload a file with CURLOPT_POSTFIELDS.  

然后官网的手册中的最后一条评论,仿佛是看不下去,写了个处理上传的程序

PHP代码
  1. There are "@" issue on multipart POST requests.  
  2.   
  3. Solution for PHP 5.5 or later:  
  4. - Enable CURLOPT_SAFE_UPLOAD.  
  5. - Use CURLFile instead of "@".  
  6.   
  7. Solution for PHP 5.4 or earlier:  
  8. - Build up multipart content body by youself.  
  9. - Change "Content-Type" header by yourself.  
  10.   
  11. The following snippet will help you :D  
  12.   
  13. <?php  
  14.   
  15. /** 
  16. * For safe multipart POST request for PHP5.3 ~ PHP 5.4. 
  17.  
  18. * @param resource $ch cURL resource 
  19. * @param array $assoc "name => value" 
  20. * @param array $files "name => path" 
  21. * @return bool 
  22. */  
  23. function curl_custom_postfields($charray $assoc = array(), array $files = array()) {  
  24.       
  25.     // invalid characters for "name" and "filename"  
  26.     static $disallow = array("\0""\"""\r""\n");  
  27.       
  28.     // build normal parameters  
  29.     foreach ($assoc as $k => $v) {  
  30.         $k = str_replace($disallow"_"$k);  
  31.         $body[] = implode("\r\n"array(  
  32.             "Content-Disposition: form-data; name=\"{$k}\"",  
  33.             "",  
  34.             filter_var($v),   
  35.         ));  
  36.     }  
  37.       
  38.     // build file parameters  
  39.     foreach ($files as $k => $v) {  
  40.         switch (true) {  
  41.             case false === $v = realpath(filter_var($v)):  
  42.             case !is_file($v):  
  43.             case !is_readable($v):  
  44.                 continue// or return false, throw new InvalidArgumentException  
  45.         }  
  46.         $data = file_get_contents($v);  
  47.         $v = call_user_func("end"explode(DIRECTORY_SEPARATOR, $v));  
  48.         $k = str_replace($disallow"_"$k);  
  49.         $v = str_replace($disallow"_"$v);  
  50.         $body[] = implode("\r\n"array(  
  51.             "Content-Disposition: form-data; name=\"{$k}\"; filename=\"{$v}\"",  
  52.             "Content-Type: application/octet-stream",  
  53.             "",  
  54.             $data,   
  55.         ));  
  56.     }  
  57.       
  58.     // generate safe boundary   
  59.     do {  
  60.         $boundary = "---------------------" . md5(mt_rand() . microtime());  
  61.     } while (preg_grep("/{$boundary}/"$body));  
  62.       
  63.     // add boundary for each parameters  
  64.     array_walk($bodyfunction (&$partuse ($boundary) {  
  65.         $part = "--{$boundary}\r\n{$part}";  
  66.     });  
  67.       
  68.     // add final boundary  
  69.     $body[] = "--{$boundary}--";  
  70.     $body[] = "";  
  71.       
  72.     // set options  
  73.     return @curl_setopt_array($charray(  
  74.         CURLOPT_POST       => true,  
  75.         CURLOPT_POSTFIELDS => implode("\r\n"$body),  
  76.         CURLOPT_HTTPHEADER => array(  
  77.             "Expect: 100-continue",  
  78.             "Content-Type: multipart/form-data; boundary={$boundary}"// change Content-Type  
  79.         ),  
  80.     ));  
  81. }  

好吧,其实多文件上传用这样的方式就挺好。