protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId) { parent::_associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId); $CNF =& $this->_oModule->_oConfig->CNF; $sData = ''; $sExif = ''; $aExif = false; $aFile = $oStorage->getFile($iFileId); if (0 == strncmp('image/', $aFile['mime_type'], 6)) { $oImageReize = BxDolImageResize::getInstance(); $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_BIG']); $a = $oImageReize->getImageSize($oTranscoder->getFileUrl($iFileId)); $sData = isset($a['w']) && isset($a['h']) ? $a['w'] . 'x' . $a['h'] : ''; if ($aExif = $oImageReize->getExifInfo($oStorage->getFileUrlById($iFileId))) { $a = array('Make', 'Model', 'FocalLength', 'ShutterSpeedValue', 'ExposureTime', 'ISOSpeedRatings', 'Orientation', 'Artist', 'Copyright', 'Flash', 'WhiteBalance', 'DateTimeOriginal', 'DateTimeDigitized', 'ExifVersion', 'COMPUTED', 'GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude', 'GPSAltitudeRef', 'GPSAltitude', 'GPSTimeStamp', 'GPSImgDirectionRef', 'GPSImgDirection', 'GPSDateStamp'); $aExifFiltered = array(); foreach ($a as $sIndex) { if (isset($aExif[$sIndex])) { $aExifFiltered[$sIndex] = $aExif[$sIndex]; } } $sExif = serialize($aExifFiltered); } } if (false === $this->_oModule->_oDb->associateFileWithContent($iContentId, $iFileId, $this->getCleanValue('title-' . $iFileId), $sData, $sExif)) { return; } $aMediaInfo = $this->_oModule->_oDb->getMediaInfoSimpleByFileId($iFileId); if ($aMediaInfo && !empty($CNF['OBJECT_METATAGS_MEDIA'])) { $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA']); if ($oMetatags->keywordsIsEnabled()) { $oMetatags->keywordsAdd($aMediaInfo['id'], $aMediaInfo['title']); } } if ($aMediaInfo && isset($aExif['Make']) && !empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) { $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']); if ($oMetatags->keywordsIsEnabled()) { $oMetatags->keywordsAddOne($aMediaInfo['id'], $oMetatags->keywordsCameraModel($aExif)); } } }
protected function applyFilter_Resize($sFile, $aParams) { $o = BxDolImageResize::getInstance(); $o->removeCropOptions(); $o->setSize(isset($aParams['w']) ? round($aParams['w'] * $this->getDevicePixelRatio()) : null, isset($aParams['h']) ? round($aParams['h'] * $this->getDevicePixelRatio()) : null); if (isset($aParams['crop_resize']) && $aParams['crop_resize']) { $o->setAutoCrop(true); } elseif (isset($aParams['square_resize']) && $aParams['square_resize']) { $o->setSquareResize(true); } else { $o->setSquareResize(false); } if (IMAGE_ERROR_SUCCESS == $o->resize($sFile)) { return true; } return false; }
/** * Get video size. * It generated image from the video and returns size of the image. * @param $sFile path to the video file * @return array where 'w' key is width and 'h' key is height */ protected function _getVideoSize($sFile) { $sFileOut = $this->getTmpFilename('.jpg'); $bRet = $this->_convertVideo($sFile, $sFileOut, '.jpg', array(), array('ss' => 0, 'vframes' => 1, 'f' => 'image2', 'an' => ' ')); if (!$bRet) { @unlink($sFileOut); return false; } bx_import('BxDolImageResize'); $oImage = BxDolImageResize::getInstance(); $aSize = $oImage->getImageSize($sFileOut); @unlink($sFileOut); return $aSize; }
/** * page code function */ function PageCompMainCode() { $sFile = ''; $sImgTmpDir = BX_DIRECTORY_PATH_TMP . 'img_resize_'; $sImgSrcName = 'landscape.jpg'; $sImgSrcDir = BX_DIRECTORY_PATH_ROOT . 'samples/img/' . $sImgSrcName; $o = BxDolImageResize::getInstance(); $o->removeCropOptions(); switch (bx_get('action')) { case 'img_src': $sFile = $sImgSrcDir; break; case 'img_resize': $sFile = $sImgTmpDir . 'resize_' . $sImgSrcName; $o->setSize(200, 150); $res = $o->resize($sImgSrcDir, $sFile); break; case 'img_resize_autocrop': $sFile = $sImgTmpDir . 'resize_autocrop_' . $sImgSrcName; $o->setSize(200, 150); $o->setAutoCrop(true); $res = $o->resize($sImgSrcDir, $sFile); break; case 'img_resize_square': $sFile = $sImgTmpDir . 'resize_square_' . $sImgSrcName; $o->setSize(150, 150); $o->setSquareResize(true); $res = $o->resize($sImgSrcDir, $sFile); break; case 'img_resize_w': $sFile = $sImgTmpDir . 'resize_w_' . $sImgSrcName; $o->setSize(150, null); $res = $o->resize($sImgSrcDir, $sFile); break; case 'img_resize_h': $sFile = $sImgTmpDir . 'resize_h_' . $sImgSrcName; $o->setSize(null, 150); $res = $o->resize($sImgSrcDir, $sFile); break; case 'img_grayscale': $sFile = $sImgTmpDir . 'grayscale_' . $sImgSrcName; $res = $o->grayscale($sImgSrcDir, $sFile); break; case 'img_watermark': $sFile = $sImgTmpDir . 'watermark_' . $sImgSrcName; $res = $o->applyWatermark($sImgSrcDir, $sFile, BX_DIRECTORY_PATH_ROOT . 'samples/img/ussr.gif', 50, 'bottom-right', 0, 0, 0.2); break; } if ($sFile) { if (isset($res) && IMAGE_ERROR_SUCCESS !== $res) { echo $o->getError(); exit; } else { header("Content-Type: image/jpeg"); readfile($sFile); } exit; } ob_start(); ?> Source:<br /> <img border=1 style="max-width:300px;" src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_src" /> <hr class="bx-def-hr" /> Resized:<br /> <img border=1 src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_resize" /> <hr class="bx-def-hr" /> Autocrop resized:<br /> <img border=1 src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_resize_autocrop" /> <hr class="bx-def-hr" /> Square resized:<br /> <img border=1 src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_resize_square" /> <hr class="bx-def-hr" /> Resized by width:<br /> <img border=1 src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_resize_w" /> <hr class="bx-def-hr" /> Resized by height:<br /> <img border=1 src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_resize_h" /> <hr class="bx-def-hr" /> Grayscaled:<br /> <img border=1 style="max-width:300px;" src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_grayscale" /> <hr class="bx-def-hr" /> Watermark:<br /> <img border=1 style="max-width:300px;" src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_watermark" /> <hr class="bx-def-hr" /> Average color:<br /> <?php $a = $o->getAverageColor($sImgSrcDir); echo '<pre>' . print_r($a, 1) . '</pre>'; ?> <hr class="bx-def-hr" /> Is image:<br /> <?php echo "[" . $o->isAllowedImage($sImgSrcDir) . "]"; return DesignBoxContent("Image Resize", ob_get_clean(), BX_DB_PADDING_DEF); }
protected function applyFilter_Grayscale($sFile, $aParams) { $o = BxDolImageResize::getInstance(); $o->removeCropOptions(); if (IMAGE_ERROR_SUCCESS == $o->grayscale($sFile)) { return true; } return false; }
/** * page code function */ function PageCompMainCode() { $sFile = ''; $sImgTmpDir = BX_DIRECTORY_PATH_TMP . 'img_resize_'; $sImgSrcDir = BX_DIRECTORY_PATH_ROOT . 'samples/img/landscape.jpg'; $o = BxDolImageResize::getInstance(); $o->removeCropOptions(); $o->setJpegOutput(true); switch (bx_get('action')) { case 'img_src': $sFile = $sImgSrcDir; break; case 'img_resize': $sFile = $sImgTmpDir . 'resize.jpg'; $o->setSize(200, 150); $o->resize($sImgSrcDir, $sFile); break; case 'img_resize_autocrop': $sFile = $sImgTmpDir . 'resize_autocrop.jpg'; $o->setSize(200, 150); $o->setAutoCrop(true); $o->resize($sImgSrcDir, $sFile); break; case 'img_resize_square': $sFile = $sImgTmpDir . 'resize_square.jpg'; $o->setSize(150, 150); $o->setSquareResize(true); $o->resize($sImgSrcDir, $sFile); break; case 'img_grayscale': $sFile = $sImgTmpDir . 'grayscale.jpg'; $o->grayscale($sImgSrcDir, $sFile); break; } if ($sFile) { header("Content-Type: image/jpeg"); readfile($sFile); exit; } ob_start(); ?> Source:<br /> <img border=1 style="max-width:300px;" src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_src" /> <hr class="bx-def-hr" /> Resized:<br /> <img border=1 src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_resize" /> <hr class="bx-def-hr" /> Autocrop resized:<br /> <img border=1 src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_resize_autocrop" /> <hr class="bx-def-hr" /> Square resized:<br /> <img border=1 src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_resize_square" /> <hr class="bx-def-hr" /> Grayscaled:<br /> <img border=1 style="max-width:300px;" src ="<?php echo BX_DOL_URL_ROOT; ?> samples/image_resize.php?action=img_grayscale" /> <?php return DesignBoxContent("Image Resize", ob_get_clean(), BX_DB_PADDING_DEF); }
protected function applyFilter_Resize($sFile, $aParams) { bx_import('BxDolImageResize'); $o = BxDolImageResize::getInstance(); $o->removeCropOptions(); // if only one dimension specified - automatically calculate another dimension if (isset($aParams['w']) && !isset($aParams['h']) || isset($aParams['h']) && !isset($aParams['w'])) { $a = $o->getImageSize($sFile); $fRatio = $a['w'] / $a['h']; if (isset($aParams['w'])) { $aParams['h'] = round($aParams['w'] / $fRatio); } else { $aParams['w'] = round($aParams['h'] * $fRatio); } } if (isset($aParams['w']) && isset($aParams['h'])) { $o->setSize($aParams['w'] * $this->getDevicePixelRatio(), $aParams['h'] * $this->getDevicePixelRatio()); } if (isset($aParams['crop_resize']) && $aParams['crop_resize']) { $o->setAutoCrop(true); } elseif (isset($aParams['square_resize']) && $aParams['square_resize']) { $o->setSquareResize(true); } else { $o->setSquareResize(false); } $this->_checkForceType($o, $aParams); if (IMAGE_ERROR_SUCCESS == $o->resize($sFile)) { return true; } return false; }