/** * validateThumbAndMediaInfo validate and manipulate a thumbnail params according to the given media info * * @param thumbParams $thumbParams * @param mediaInfo $mediaInfo * @param string $errDescription * @return thumbParamsOutput or null for fail */ protected static function validateThumbAndMediaInfo(thumbParams $thumbParams, mediaInfo $mediaInfo = null, &$errDescription) { $thumbParamsOutput = new thumbParamsOutput(); $thumbParamsOutput->setFlavorParamsId($thumbParams->getId()); $thumbParamsOutput->setFlavorParamsVersion($thumbParams->getVersion()); $thumbParamsOutput->setName($thumbParams->getName()); $thumbParamsOutput->setTags($thumbParams->getTags()); $thumbParamsOutput->setDescription($thumbParams->getDescription()); $thumbParamsOutput->setReadyBehavior($thumbParams->getReadyBehavior()); $thumbParamsOutput->setFormat($thumbParams->getFormat()); $thumbParamsOutput->setWidth($thumbParams->getWidth()); $thumbParamsOutput->setHeight($thumbParams->getHeight()); $thumbParamsOutput->setConversionEngines($thumbParams->getConversionEngines()); $thumbParamsOutput->setConversionEnginesExtraParams($thumbParams->getConversionEnginesExtraParams()); $thumbParamsOutput->setOperators($thumbParams->getOperators()); $thumbParamsOutput->setEngineVersion($thumbParams->getEngineVersion()); $thumbParamsOutput->setFileExt('jpg'); $thumbParamsOutput->setCropType($thumbParams->getCropType()); $thumbParamsOutput->setQuality($thumbParams->getQuality()); $thumbParamsOutput->setCropX($thumbParams->getCropX()); $thumbParamsOutput->setCropY($thumbParams->getCropY()); $thumbParamsOutput->setCropWidth($thumbParams->getCropWidth()); $thumbParamsOutput->setCropHeight($thumbParams->getCropHeight()); $thumbParamsOutput->setCropProvider($thumbParams->getCropProvider()); $thumbParamsOutput->setCropProviderData($thumbParams->getCropProviderData()); $thumbParamsOutput->setVideoOffset($thumbParams->getVideoOffset()); $thumbParamsOutput->setWidth($thumbParams->getWidth()); $thumbParamsOutput->setHeight($thumbParams->getHeight()); $thumbParamsOutput->setScaleWidth($thumbParams->getScaleWidth()); $thumbParamsOutput->setScaleHeight($thumbParams->getScaleHeight()); $thumbParamsOutput->setBackgroundColor($thumbParams->getBackgroundColor()); if ($mediaInfo) { if ($thumbParamsOutput->getVideoOffset() && $mediaInfo->getVideoDuration()) { $videoDurationSec = floor($mediaInfo->getVideoDuration() / 1000); if ($thumbParamsOutput->getVideoOffset() > $videoDurationSec) { $thumbParamsOutput->setVideoOffset($videoDurationSec); } } } return $thumbParamsOutput; }
<?php require_once __DIR__ . '/../bootstrap.php'; $thumbParams = new thumbParams(); $thumbParams->setVersion(1); $thumbParams->setPartnerId(0); $thumbParams->setTags(''); $thumbParams->setIsDefault(false); $thumbParams->setFormat(thumbParams::CONTAINER_FORMAT_JPG); //$thumbParams->setWidth(800); //$thumbParams->setHeight(600); $thumbParams->setSourceParamsId(3); $thumbParams->setCropType(1); //$thumbParams->setQuality(100); $thumbParams->setCropX(100); $thumbParams->setCropY(100); //$thumbParams->setCropWidth(); //$thumbParams->setCropHeight(); //$thumbParams->setCropProvider(); //$thumbParams->setCropProviderData(); $thumbParams->setVideoOffset(2); //$thumbParams->setScaleWidth(); //$thumbParams->setScaleHeight(); //$thumbParams->setBackgroundColor(); $thumbParams->setName($thumbParams->getWidth() . ' x ' . $thumbParams->getHeight()); $thumbParams->setDescription($thumbParams->getName()); $thumbParams->save(); echo "Done\n";
/** * validateThumbAndMediaInfo validate and manipulate a thumbnail params according to the given media info * * @param thumbParams $thumbParams * @param mediaInfo $mediaInfo * @param string $errDescription * @return thumbParamsOutput or null for fail */ protected static function validateThumbAndMediaInfo(thumbParams $thumbParams, mediaInfo $mediaInfo = null, &$errDescription, $srcAsset = null) { $thumbParamsOutput = new thumbParamsOutput(); $thumbParamsOutput->setFlavorParamsId($thumbParams->getId()); $thumbParamsOutput->setFlavorParamsVersion($thumbParams->getVersion()); $thumbParamsOutput->setName($thumbParams->getName()); $thumbParamsOutput->setTags($thumbParams->getTags()); $thumbParamsOutput->setDescription($thumbParams->getDescription()); $thumbParamsOutput->setReadyBehavior($thumbParams->getReadyBehavior()); $thumbParamsOutput->setFormat($thumbParams->getFormat()); $thumbParamsOutput->setWidth($thumbParams->getWidth()); $thumbParamsOutput->setHeight($thumbParams->getHeight()); $thumbParamsOutput->setConversionEngines($thumbParams->getConversionEngines()); $thumbParamsOutput->setConversionEnginesExtraParams($thumbParams->getConversionEnginesExtraParams()); $thumbParamsOutput->setOperators($thumbParams->getOperators()); $thumbParamsOutput->setEngineVersion($thumbParams->getEngineVersion()); $extensionTypes = kConf::hasParam('image_file_ext') ? kConf::get('image_file_ext') : array(); $ext = null; if ($srcAsset) { $ext = $srcAsset->getFileExt(); } if (!is_null($ext) && in_array($ext, $extensionTypes)) { $thumbParamsOutput->setFileExt($ext); } else { $thumbParamsOutput->setFileExt('jpg'); } $thumbParamsOutput->setRotate($mediaInfo ? $mediaInfo->getVideoRotation() : null); $thumbParamsOutput->setCropType($thumbParams->getCropType()); $thumbParamsOutput->setQuality($thumbParams->getQuality()); $thumbParamsOutput->setCropX($thumbParams->getCropX()); $thumbParamsOutput->setCropY($thumbParams->getCropY()); $thumbParamsOutput->setCropWidth($thumbParams->getCropWidth()); $thumbParamsOutput->setCropHeight($thumbParams->getCropHeight()); $thumbParamsOutput->setCropProvider($thumbParams->getCropProvider()); $thumbParamsOutput->setCropProviderData($thumbParams->getCropProviderData()); $thumbParamsOutput->setVideoOffset($thumbParams->getVideoOffset()); $thumbParamsOutput->setWidth($thumbParams->getWidth()); $thumbParamsOutput->setHeight($thumbParams->getHeight()); $thumbParamsOutput->setScaleWidth($thumbParams->getScaleWidth()); $thumbParamsOutput->setScaleHeight($thumbParams->getScaleHeight()); $thumbParamsOutput->setBackgroundColor($thumbParams->getBackgroundColor()); if ($mediaInfo && $mediaInfo->getVideoDuration()) { $videoDurationSec = floor($mediaInfo->getVideoDuration() / 1000); if ($thumbParamsOutput->getVideoOffset()) { if ($thumbParamsOutput->getVideoOffset() > $videoDurationSec) { $thumbParamsOutput->setVideoOffset($videoDurationSec); } } elseif (!is_null($thumbParams->getVideoOffsetInPercentage())) { $percentage = $thumbParams->getVideoOffsetInPercentage() / 100; $thumbParamsOutput->setVideoOffset(floor($videoDurationSec * $percentage)); } } return $thumbParamsOutput; }