jyggen/youtubethumb

此包已被弃用且不再维护。没有建议的替代包。

一个PHP类,用于帮助您加载、编辑和保存从YouTube视频中的缩略图。

v2.1 2013-02-27 14:02 UTC

This package is auto-updated.

Last update: 2022-03-16 01:51:00 UTC


README

一个PHP类,用于帮助您加载、编辑和保存从YouTube视频中的缩略图。

在Packagist/Composer上找到YoutubeThumb

示例

use jyggen\Youtube\Thumbnail;

// Load a thumbnail and save it to disk.
Thumbnail::forge('83fJ7hlZkpA')->save('my_path/');

// Maybe we wanna do some changes aswell. Retrieve the previously forged instance.
$thumb = Thumbnail::instance('83fJ7hlZkpA');

// Get the Thumbnail's GD resource.
$data  = $thumb->getData();

// Create a new GD resource and copy a portion of the thumbnail into our new image.
$dest = imagecreatetruecolor(80, 40);
imagecopy($dest, $data, 0, 0, 20, 13, 80, 40);

// Set our old thumbnail to the new resized one.
$thumb->setData($dest);

// Oh shit, did we fudge up something? Reset the image to its original state.
$thumb->reset();

// We want to save the image again, but with a different name and extension.
$thumb->setName('my_awesome_thumbnail');
$thumb->save('my_path/', 'gif');

缩略图对象

静态方法

  • forge(string $youtubeId)
    创建一个新的缩略图实例。
  • instance(string $youtubeId)
    检索现有的缩略图实例。

方法

  • reset()
    将缩略图重置为其原始状态。
  • save(string $path, string $extension = 'png')
    将缩略图保存到磁盘。
  • getData()
    获取缩略图的GD资源。
  • setData(resource $data)
    设置缩略图的GD资源。
  • getName()
    获取不带扩展名的输出名称。
  • setName(string $name)
    设置不带扩展名的输出名称。