Image.php 3.0 KB

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