Skip to content

Instantly share code, notes, and snippets.

@Djuki
Last active December 18, 2015 15:28
Show Gist options
  • Save Djuki/5804506 to your computer and use it in GitHub Desktop.
Save Djuki/5804506 to your computer and use it in GitHub Desktop.
Create youtube image with play button and scrubber
<?php
/**
* Get image for video preview
*
* @param $videoId
*
* @return string
*/
public function createVideoImage($videoId)
{
$tempImage = $this->createVideoTempImage($videoId);
$mainImage = ImageWorkshop::initFromPath($tempImage);
$width = $mainImage->getWidth();
$playButtonPath = Config::get('tools.video.play_button');
$playImage = ImageWorkshop::initFromPath($playButtonPath);
$scrubberPath = Config::get('tools.video.scrubber');
$scrubberImage = ImageWorkshop::initFromPath($scrubberPath);
$playImage->resizeInPixel($width, null, true);
$scrubberImage->resizeInPixel($width, null, true);
$mainImage->addLayer(2, $playImage);
$mainImage->addLayer(3, $scrubberImage, 0, 0 , 'LB');
$mainImage->mergeAll();
$imageName = md5($videoId).'.jpg';
$mainImage->save($this->getImageSaveFolder(), $imageName, true, null, 100);
unlink($tempImage);
return $imageName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment