杜郎俊赏 - dujun.io

建站之视频处理

借助 ffmpeg 扩展处理视频。包括自动旋转、截图、转换格式等。 ubuntu 下安装扩展 sudo apt-get install ffmpeg 获取视频尺寸、旋转角度 /** * /usr/bin/ffprobe video.mp4 -show_streams -print_format json */ public static function info($video) { $raw = shell_exec(sprintf('%s %s -show_streams -print_format json', self::ffprobe(), $video)); if (empty($raw) || !($raw = json_decode($raw, true)) || empty($raw['streams'])) { return fals...

2017-05-18

建站之友好时间显示

public function format($time) { if (invalid_integer($time)) { return ''; } $now = time(); $today = strtotime(date('Y-m-d', $now)); $tmp = $now - $time; if (60 > $tmp) { return '刚刚'; } elseif (3600 > $tmp) { return floor($tmp / 60) . ' 分钟前'; } elseif (86400 > $tmp) { return floor($tmp / 3600) . ' 小时前'; } $time = strtotime(date...

2017-05-18

建站之阿里云邮件推送

评论被回复时,如果评论者填了邮箱,则向其发送通知邮件。使用阿里云的邮件推送。每日免费额度 200 封。 /** * 发送阿里云邮件 */ class Util_Mail { private static $url, $accessId, $accessSecret, $account, $name; public static function send($title, $content, $receiver = null) { if (empty($title) || empty($content)) { return false; } self::init(); if (is_null($receiver)) { $receiver = Commo...

2017-05-18

建站之图片缩略图

难点在于,gif 图片直接截缩略图可能有巨大噪音,所以改为截取第一帧。 //生成缩略图 public static function createThumb($imagePath) { try { if (!($imagePath = File::exist($imagePath))) { return false; } if (is_mobile()) { //移动端生成更小的图 $path = $imagePath . '_s.jpg'; $maxWidth = 147; } else { $path = $imagePath . '_m.jpg'; $maxWidth =...

2017-05-18

建站之图片大小调整

借助 imagemagick 扩展调整图片大小。 $maxSize = 2097152; //图片限制 2M $maxWidth = 1024; $maxHeight = 768; try { do { $imagick = new Imagick($imagePath); if ($maxSize >= $imagick->getImageLength()) { break; } if ($maxWidth < $imagick->getImageWidth()) { $imagick->scaleImage($maxWidth, 0); } elseif ($maxHeight < $imagick->getImageHeight()) {...

2017-05-18

634封面

2017-05-18

建站之图片旋转

手机拍摄的照片存在旋转的问题,借助 imagemagick 扩展解决。 安装扩展: sudo apt-get install imagemagick sudo apt-get install php-imagick 旋转图片: try { $imagick = new Imagick($imagePath); if ($orientation = $imagick->getImageOrientation()) { switch ($orientation) { case 8: //逆时针90° $degrees = -90; break; case 3: //180° $degrees = -180...

2017-05-18

建站之 gravatar 缓存

为解决 gravatar 头像访问慢和被墙的问题,可以做本地图片备份。 $url = 'https://secure.gravatar.com/avatar/' . md5($mail) . '?s=36&r=G&d=404'; $header = get_headers($url); if (empty($header) || false === strpos($header[0], '200')) { //此邮箱不存在 gravatar 头像 } else { //抓取头像图片 $image = file_get_contents($url); }

2017-05-18

建站之 yaf 框架

用 yaf 框架重新开发了整站。 ubuntu 下安装命令: sudo apt-get install php7.0-dev sudo pecl install yaf 修改php.ini,追加内容 [yaf] extension=yaf.so yaf.use_namespace=1 yaf.environ=develop

2017-05-17

建站之动态密码

为了安全,后台登录增加了动态密码。基于 GoogleAuthenticator 实现。 用法很简单,看 github 说明即会。 创建二维码时需要翻墙访问 google。

2017-05-05

分页: 1 2 3 4 5 6 7 8 9 10 11 12 13