ngmy/media-thumbnail-url

Get thumbnail URL for a given media URL. Supports Instagram and YouTube.

dev-master 2022-11-21 00:26 UTC

This package is auto-updated.

Last update: 2024-11-21 04:17:47 UTC


README

test coverage

Get thumbnail URL for a given media URL. Supports Instagram and YouTube.

Installation

composer require ngmy/media-thumbnail-url

Usage

Instagram

use Ngmy\MediaThumbnailUrl\Generator;
use Ngmy\MediaThumbnailUrl\Strategy\InstagramStrategy;
use Ngmy\MediaThumbnailUrl\Strategy\InstagramStrategyParameter\InstagramThumbnailSize;

$mediaUrl = 'https://www.instagram.com/p/CkRFMwSjajp/';
$strategy = new InstagramStrategy(
    thumbnailSize: InstagramThumbnailSize::Thumbnail,
);
$generator = Generator::createFromStrategy($strategy);
$generator->generate($mediaUrl); // return '//www.instagram.com/p/CkRFMwSjajp/media?size=t'

YouTube

use Ngmy\MediaThumbnailUrl\Generator;
use Ngmy\MediaThumbnailUrl\Strategy\YoutubeStrategy;
use Ngmy\MediaThumbnailUrl\Strategy\YoutubeStrategyParameter\YoutubeThumbnailSize;
use Ngmy\MediaThumbnailUrl\Strategy\YoutubeStrategyParameter\YoutubeThumbnailFormat;

$mediaUrl = 'https://www.youtube.com/watch?v=EEixTRM5gUk';
$strategy = new YoutubeStrategy(
    thumbnailSize: YoutubeThumbnailSize::NormalQualityDefault,
    thumbnailFormat: YoutubeThumbnailFormat::Jpeg,
);
$generator = Generator::createFromStrategy($strategy);
$generator->generate($mediaUrl); // return '//img.youtube.com/vi/EEixTRM5gUk/default.jpg'

License

PHP Media Thumbnail URL is open-sourced software licensed under the MIT license.