ngmy / media-thumbnail-url
Get thumbnail URL for a given media URL. Supports Instagram and YouTube.
Fund package maintenance!
ngmy
flattr.com/@ngmy
Requires
- php: ^8.1
- league/uri: ^6.8
- league/uri-components: ^2.4
Requires (Dev)
This package is auto-updated.
Last update: 2024-11-21 04:17:47 UTC
README
Get thumbnail URL for a given media URL. Supports Instagram and YouTube.
Installation
composer require ngmy/media-thumbnail-url
Usage
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.