Thinkphp下文章管理系统icon图标功能的实现

function geticonadd($content) {
  if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
    $add = $matches[3][0];                           //获取文件地址
    $s = strripos($add, "/") - 8;
    $name = substr($add, $s);                        //获取文件名
    $name2 = substr($add, $s + 9);
    //处理图片
    $image = new \Think\Image();
    $file = "../../ueditor/php/upload/image/{$name}"; //放到服务器时请去掉前面‘../’
    if (file_exists($file)) {
      $image->open($file); 
      $width = $image->width();
      $height = $image->height();
      if ($width > $height) {
        $k = $height;
      } else {
        $k = $width;
      }
      // 先裁剪成正方形,再等比例缩放大小为100*100
      $image->thumb($k, $k, \Think\Image::IMAGE_THUMB_CENTER)
          ->thumb(100, 100)
          ->save("Public/image/icon/{$name2}");
      //$icon_add= '__PUBLIC__/upload/image/icon/{$name}';

      return $name2;
    } else {
      return '';
    }
  } else {
    return "default.jpg";
  }
}

算法思路:

  1. 从ueditor的文章内容中匹配获取图片链接字符串,从字符串中提取图片名。
  2. 获取图片文件,进行裁剪。
  3. 另存icon到指定目录,返回icon的名称
  4. 如果文章内容中没有图片,则返回默认图片名。

转载于:https://my.oschina.net/HeYuhui/blog/632454

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值