gstjohn / thumbsnag
Thumbsnag 会爬取HTML文档并找到最能代表给定页面的图片。
v1.0.1
2015-03-16 06:05 UTC
Requires
Requires (Dev)
- phpspec/phpspec: ~2.0@dev
This package is not auto-updated.
Last update: 2024-09-14 15:27:07 UTC
README
Thumbsnag 会爬取HTML文档并找到最能代表给定页面的图片。
示例
use Thumbsnag\FastImageAnalyzer; use Thumbsnag\Thumbsnag; use Thumbsnag\UrlDocument; $url = 'http://simplegifts.co'; $html = file_get_contents($url); $document = new DOMDocument(); $document->loadHTML($html); $analyzer = new FastImageAnalyzer(new FastImage()); $thumbsnag = Thumbsnag::load(new UrlDocument($doc, $url), $analyzer); $images = $thumbsnag->process();
检查后,$images
将返回类似
Array ( [1] => Thumbsnag\Image Object ( [url:Thumbsnag\Image:private] => http://simplegifts.co/image1.jpg [height:Thumbsnag\Image:private] => 565 [width:Thumbsnag\Image:private] => 849 ) [2] => Thumbsnag\Image Object ( [url:Thumbsnag\Image:private] => http://simplegifts.co/image2.png [height:Thumbsnag\Image:private] => 450 [width:Thumbsnag\Image:private] => 1162 ) )
配置
步骤 1:安装
通过Composer拉取包。
"require": { "gstjohn/thumbsnag": "~1.0" }
步骤 2:配置(如有必要)
Thumbsnag::load() 的第三个参数接受一个数组,该数组覆盖了默认配置。可用的配置选项包括
-
min_area (默认: 5000)
此选项代表为了被包含在结果集中所需的最低像素面积(宽度 x 高度)。
-
ratio_threshold (默认: 3.0)
此选项代表为了被包含在结果集中允许的最大宽度与高度的比率。
-
filename_filters (默认: "sprite", "blank", and "spacer")
此选项代表一个数组,包含不允许出现在图片文件名中的单词,以便被包含在结果集中。
致谢
许可
Thumbsnag 是开源软件,许可协议为 MIT 协议。