Image.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/WeChatDeveloper
  12. // +----------------------------------------------------------------------
  13. namespace WeMini;
  14. use WeChat\Contracts\BasicWeChat;
  15. /**
  16. * 小程序图像处理
  17. * Class Image
  18. * @package WeMini
  19. */
  20. class Image extends BasicWeChat
  21. {
  22. /**
  23. * 本接口提供基于小程序的图片智能裁剪能力
  24. * @param string $img_url 要检测的图片 url,传这个则不用传 img 参数。
  25. * @param string $img form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用穿 img_url
  26. * @return array
  27. * @throws \WeChat\Exceptions\InvalidResponseException
  28. * @throws \WeChat\Exceptions\LocalCacheException
  29. */
  30. public function aiCrop($img_url, $img)
  31. {
  32. $url = "https://api.weixin.qq.com/cv/img/aicrop?access_token=ACCESS_TOCKEN";
  33. return $this->callPostApi($url, ['img_url' => $img_url, 'img' => $img], true);
  34. }
  35. /**
  36. * 本接口提供基于小程序的条码/二维码识别的API
  37. * @param string $img_url 要检测的图片 url,传这个则不用传 img 参数。
  38. * @param string $img form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用穿 img_url
  39. * @return array
  40. * @throws \WeChat\Exceptions\InvalidResponseException
  41. * @throws \WeChat\Exceptions\LocalCacheException
  42. */
  43. public function scanQRCode($img_url, $img)
  44. {
  45. $url = "https://api.weixin.qq.com/cv/img/qrcode?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN";
  46. return $this->callPostApi($url, ['img_url' => $img_url, 'img' => $img], true);
  47. }
  48. /**
  49. * 本接口提供基于小程序的图片高清化能力
  50. * @param string $img_url 要检测的图片 url,传这个则不用传 img 参数
  51. * @param string $img form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用穿 img_url
  52. * @return array
  53. * @throws \WeChat\Exceptions\InvalidResponseException
  54. * @throws \WeChat\Exceptions\LocalCacheException
  55. */
  56. public function superresolution($img_url, $img)
  57. {
  58. $url = "https://api.weixin.qq.com/cv/img/qrcode?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN";
  59. return $this->callPostApi($url, ['img_url' => $img_url, 'img' => $img], true);
  60. }
  61. }