Image.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2015 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 麦当苗儿 <zuojiazi.cn@gmail.com> <http://www.zjzit.cn>
  10. // +----------------------------------------------------------------------
  11. namespace org;
  12. /* 缩略图相关常量定义 */
  13. define('THINKIMAGE_THUMB_SCALING', 1); //常量,标识缩略图等比例缩放类型
  14. define('THINKIMAGE_THUMB_FILLED', 2); //常量,标识缩略图缩放后填充类型
  15. define('THINKIMAGE_THUMB_CENTER', 3); //常量,标识缩略图居中裁剪类型
  16. define('THINKIMAGE_THUMB_NORTHWEST', 4); //常量,标识缩略图左上角裁剪类型
  17. define('THINKIMAGE_THUMB_SOUTHEAST', 5); //常量,标识缩略图右下角裁剪类型
  18. define('THINKIMAGE_THUMB_FIXED', 6); //常量,标识缩略图固定尺寸缩放类型
  19. /* 水印相关常量定义 */
  20. define('THINKIMAGE_WATER_NORTHWEST', 1); //常量,标识左上角水印
  21. define('THINKIMAGE_WATER_NORTH', 2); //常量,标识上居中水印
  22. define('THINKIMAGE_WATER_NORTHEAST', 3); //常量,标识右上角水印
  23. define('THINKIMAGE_WATER_WEST', 4); //常量,标识左居中水印
  24. define('THINKIMAGE_WATER_CENTER', 5); //常量,标识居中水印
  25. define('THINKIMAGE_WATER_EAST', 6); //常量,标识右居中水印
  26. define('THINKIMAGE_WATER_SOUTHWEST', 7); //常量,标识左下角水印
  27. define('THINKIMAGE_WATER_SOUTH', 8); //常量,标识下居中水印
  28. define('THINKIMAGE_WATER_SOUTHEAST', 9); //常量,标识右下角水印
  29. /**
  30. * 图片处理驱动类,可配置图片处理库
  31. * 目前支持GD库和imagick
  32. * @author 麦当苗儿 <zuojiazi.cn@gmail.com>
  33. */
  34. class Image
  35. {
  36. /**
  37. * 图片资源
  38. * @var resource
  39. */
  40. private static $im;
  41. /**
  42. * 初始化方法,用于实例化一个图片处理对象
  43. *
  44. * @param string $type 要使用的类库,默认使用GD库
  45. * @param null $imgname
  46. *
  47. * @return resource
  48. */
  49. public static function init($type = 'Gd', $imgname = null)
  50. {
  51. /* 引入处理库,实例化图片处理对象 */
  52. $class = '\\org\\image\\driver\\' . ucwords($type);
  53. self::$im = new $class($imgname);
  54. return self::$im;
  55. }
  56. // 调用驱动类的方法
  57. public static function __callStatic($method, $params)
  58. {
  59. self::$im || self::init();
  60. return call_user_func_array([self::$im, $method], $params);
  61. }
  62. }