function actionCropPerform($iPhotoID) { header('Content-Type:text/html; charset=utf-8'); $aInfo = $this->_oDb->getFileInfo(array('fileId' => $iPhotoID)); if (empty($aInfo)) { die(json_encode(array('status' => 'error', 'message' => _t('_sys_media_not_found')))); } if (!$this->isAllowedEdit($aInfo)) { die(json_encode(array('status' => 'error', 'message' => _t('_Access denied')))); } $o = BxDolImageResize::instance(); $sSrcFileName = $this->_oConfig->getFilesPath() . $aInfo['medID'] . str_replace('{ext}', $aInfo['medExt'], $this->_oConfig->aFilesConfig['original']['postfix']); $sTmpFileName = tempnam(BX_DIRECTORY_PATH_TMP, $this->_oConfig->getMainPrefix()); $bCropResult = $o->crop((double) $_POST['imgW'], (double) $_POST['imgH'], (double) $_POST['imgX1'], (double) $_POST['imgY1'], (double) $_POST['cropW'], (double) $_POST['cropH'], -(double) $_POST['rotation'], $sSrcFileName, $sTmpFileName); if (IMAGE_ERROR_SUCCESS !== $bCropResult) { die(json_encode(array('status' => 'error', 'message' => $o->getError()))); } $_POST['extra_param_album'] = $aInfo['albumUri']; $aInfo['Categories'] = preg_split('/[' . CATEGORIES_DIVIDER . ']/', $aInfo['Categories'], 0, PREG_SPLIT_NO_EMPTY); bx_import('Uploader', $this->_aModule); $sClassName = $this->_oConfig->getClassPrefix() . 'Uploader'; $oUploader = new $sClassName(); $a = $oUploader->performUpload($sTmpFileName, pathinfo($sSrcFileName, PATHINFO_BASENAME), $aInfo, false); @unlink($sTmpFileName); if (!empty($a['error'])) { die(json_encode(array('status' => 'error', 'message' => $a['error']))); } $aInfoNew = $this->_oDb->getFileInfo(array('fileId' => $a['id'])); bx_import('Search', $this->_aModule); $oSearch = new BxPhotosSearch(); $sImgUrl = $oSearch->getImgUrl($aInfoNew['Hash'], 'file'); echo json_encode(array('status' => 'success', 'url' => $sImgUrl, 'redirect_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aInfoNew['medUri'])); }
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)); } } }
function _cropAvatar() { $sSrcImagePath = BX_AVA_DIR_TMP . $this->_iProfileId . BX_AVA_EXT; $sDstImagePath = BX_AVA_DIR_TMP . 'tmp' . $this->_iProfileId . BX_AVA_EXT; $o =& BxDolImageResize::instance(); $o->setJpegOutput(true); $o->setJpegQuality(getParam('bx_avatar_quality')); $o->setSize(BX_AVA_BROWSE_W, BX_AVA_BROWSE_H); if ((int) $_POST['w'] && (int) $_POST['h']) { $o->setSquareResize(false); $aSize = $o->getImageSize($sSrcImagePath); $bRet = $aSize ? $o->crop($aSize['w'], $aSize['h'], (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['w'], (int) $_POST['h'], 0, $sSrcImagePath) : IMAGE_ERROR_WRONG_TYPE; } else { $o->setSquareResize(true); $bRet = IMAGE_ERROR_SUCCESS; } if (IMAGE_ERROR_SUCCESS == $bRet && IMAGE_ERROR_SUCCESS == $o->resize($sSrcImagePath, $sDstImagePath)) { $bRet = $this->_addAvatar($sDstImagePath, true) ? IMAGE_ERROR_SUCCESS : IMAGE_ERROR_WRONG_TYPE; } if (IMAGE_ERROR_SUCCESS == $bRet) { @unlink($sSrcImagePath); return true; } @unlink($sDstImagePath); return false; }
function getWallPostOutline($aEvent, $sIcon = 'save', $aParams = array()) { $sPrefix = $this->_oConfig->getMainPrefix(); $sPrefixAlbum = $sPrefix . '_albums'; $aOwner = getProfileInfo((int) $aEvent['owner_id']); $aObjectIds = strpos($aEvent['object_id'], ',') !== false ? explode(',', $aEvent['object_id']) : array($aEvent['object_id']); rsort($aObjectIds); $iItems = count($aObjectIds); $iItemsLimit = isset($aParams['grouped']['items_limit']) ? (int) $aParams['grouped']['items_limit'] : 3; if ($iItems > $iItemsLimit) { $aObjectIds = array_slice($aObjectIds, 0, $iItemsLimit); } $bSave = false; $aContent = array(); if (!empty($aEvent['content'])) { $aContent = unserialize($aEvent['content']); } if (!isset($aContent['idims'])) { $aContent['idims'] = array(); } $sClassName = $this->_oConfig->getClassPrefix() . 'Search'; bx_import('Search', $this->_aModule); $oSearch = new $sClassName(); $sItemThumbnailType = isset($aParams['thumbnail_type']) ? $aParams['thumbnail_type'] : 'browse'; $iDeleted = 0; $aItems = $aTmplItems = array(); foreach ($aObjectIds as $iId) { $aItem = $oSearch->serviceGetItemArray($iId, $sItemThumbnailType); if (empty($aItem)) { $iDeleted++; } else { if ($aItem['status'] == 'approved' && $this->oAlbumPrivacy->check('album_view', $aItem['album_id'], $this->oModule->_iProfileId)) { if (!isset($aContent['idims'][$iId])) { $sPath = isset($aItem['file_path']) && file_exists($aItem['file_path']) ? $aItem['file_path'] : $aItem['file']; $aContent['idims'][$iId] = BxDolImageResize::instance()->getImageSize($sPath); $bSave = true; } $aItem['dims'] = $aContent['idims'][$iId]; $aItems[] = $aItem; $aItem2x = $oSearch->serviceGetItemArray($iId, $sItemThumbnailType . '2x'); $aTmplItems[] = array_merge($aItem, array('mod_prefix' => $sPrefix, 'item_width' => $aItem['dims']['w'], 'item_height' => $aItem['dims']['h'], 'item_icon' => $aItem['file'], 'item_icon_2x' => !empty($aItem2x['file']) ? $aItem2x['file'] : $aItem['file'], 'item_page' => $aItem['url'], 'item_title' => $aItem['title'])); } } } if ($iDeleted == count($aObjectIds)) { return array('perform_delete' => true); } if (empty($aOwner) || empty($aItems)) { return ""; } $aResult = array(); if ($bSave) { $aResult['save']['content'] = serialize($aContent); } $sCss = ""; if ($aEvent['js_mode']) { $sCss = $this->_oTemplate->addCss('wall_outline.css', true); } else { $this->_oTemplate->addCss('wall_outline.css'); } $iOwner = (int) $aEvent['owner_id']; $sOwner = getNickName($iOwner); $sOwnerLink = getProfileLink($iOwner); //--- Grouped events $iItems = count($aItems); if ($iItems > 1) { $aExtra = unserialize($aEvent['content']); $sAlbumUri = $aExtra['album']; $oAlbum = new BxDolAlbums($sPrefix); $aAlbumInfo = $oAlbum->getAlbumInfo(array('fileUri' => $sAlbumUri, 'owner' => $iOwner)); $oAlbumCmts = new BxTemplCmtsView($sPrefixAlbum, $aAlbumInfo['ID']); $aAlbumInfo['comments_count'] = (int) $oAlbumCmts->getObjectCommentsCount(); $aAlbumInfo['Url'] = $oSearch->getCurrentUrl('album', $aAlbumInfo['ID'], $aAlbumInfo['Uri']) . '/owner/' . getUsername($iOwner); $sTmplName = isset($aParams['templates']['grouped']) ? $aParams['templates']['grouped'] : 'modules/boonex/wall/|outline_item_image_grouped.html'; $aResult['content'] = $sCss . $this->_oTemplate->parseHtmlByName($sTmplName, array('mod_prefix' => $sPrefix, 'mod_icon' => $sIcon, 'user_name' => $sOwner, 'user_link' => $sOwnerLink, 'bx_repeat:items' => $aTmplItems, 'album_url' => $aAlbumInfo['Url'], 'album_title' => $aAlbumInfo['Caption'], 'album_description' => strmaxtextlen($aAlbumInfo['Description'], 200), 'album_comments' => (int) $aAlbumInfo['comments_count'] > 0 ? _t('_wall_n_comments', $aAlbumInfo['comments_count']) : _t('_wall_no_comments'), 'album_comments_link' => $aAlbumInfo['Url'] . '#cmta-' . $sPrefixAlbum . '-' . $aAlbumInfo['ID'], 'post_id' => $aEvent['id'], 'post_ago' => $aEvent['ago'])); return $aResult; } //--- Single public event $aItem = $aItems[0]; $aTmplItem = $aTmplItems[0]; $sTmplName = isset($aParams['templates']['single']) ? $aParams['templates']['single'] : 'modules/boonex/wall/|outline_item_image.html'; $aResult['content'] = $sCss . $this->_oTemplate->parseHtmlByName($sTmplName, array_merge($aTmplItem, array('mod_prefix' => $sPrefix, 'mod_icon' => $sIcon, 'user_name' => $sOwner, 'user_link' => $sOwnerLink, 'item_page' => $aItem['url'], 'item_title' => $aItem['title'], 'item_description' => strmaxtextlen($aItem['description'], 200), 'item_comments' => (int) $aItem['comments_count'] > 0 ? _t('_wall_n_comments', $aItem['comments_count']) : _t('_wall_no_comments'), 'item_comments_link' => $aItem['url'] . '#cmta-' . $sPrefix . '-' . $aItem['id'], 'post_id' => $aEvent['id'], 'post_ago' => $aEvent['ago']))); return $aResult; }
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; }
function _serviceGetWallPostOutline($aEvent, $sIcon, $aParams = array()) { $iNoPhotoWidth = $iNoPhotoHeight = 140; $sNoPhoto = $this->_oTemplate->getImageUrl('no-image-thumb.png'); $sBaseUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/'; $aOwner = db_assoc_arr("SELECT `ID` AS `id`, `NickName` AS `username` FROM `Profiles` WHERE `ID`='" . (int) $aEvent['owner_id'] . "' LIMIT 1"); $aObjectIds = strpos($aEvent['object_id'], ',') !== false ? explode(',', $aEvent['object_id']) : array($aEvent['object_id']); rsort($aObjectIds); $iItems = count($aObjectIds); $iItemsLimit = isset($aParams['grouped']['items_limit']) ? (int) $aParams['grouped']['items_limit'] : 3; if ($iItems > $iItemsLimit) { $aObjectIds = array_slice($aObjectIds, 0, $iItemsLimit); } $bSave = false; $aContent = array(); if (!empty($aEvent['content'])) { $aContent = unserialize($aEvent['content']); } if (!isset($aContent['idims'])) { $aContent['idims'] = array(); } $iDeleted = 0; $aItems = $aTmplItems = array(); foreach ($aObjectIds as $iId) { $aItem = $this->_oDb->getEntryByIdAndOwner($iId, $aEvent['owner_id'], 1); if (empty($aItem)) { $iDeleted++; } else { if ($aItem[$this->_oDb->_sFieldStatus] == 'approved' && $aParams['obj_privacy']->check($aParams['txt_privacy_view_event'], $iId, $this->_iProfileId)) { $aItem['thumb_file'] = ''; $aItem['thumb_dims'] = array(); if ($aItem[$this->_oDb->_sFieldThumb]) { $aImage = BxDolService::call('photos', 'get_entry', array($aItem[$this->_oDb->_sFieldThumb], 'browse'), 'Search'); if (!empty($aImage)) { if (!isset($aContent['idims'][$iId])) { $sPath = isset($aImage['file_path']) && file_exists($aImage['file_path']) ? $aImage['file_path'] : $aImage['file']; $aContent['idims'][$iId] = BxDolImageResize::instance()->getImageSize($sPath); $bSave = true; } $aItem['thumb_file'] = $aImage['file']; $aItem['thumb_dims'] = $aContent['idims'][$iId]; } } $aItem[$this->_oDb->_sFieldUri] = $sBaseUrl . $aItem[$this->_oDb->_sFieldUri]; $aItems[] = $aItem; $aTmplItems[] = array('mod_prefix' => $this->_sPrefix, 'item_width' => isset($aItem['thumb_dims']['w']) ? $aItem['thumb_dims']['w'] : $iNoPhotoWidth, 'item_height' => isset($aItem['thumb_dims']['h']) ? $aItem['thumb_dims']['h'] : $iNoPhotoHeight, 'item_icon' => !empty($aItem['thumb_file']) ? $aItem['thumb_file'] : $sNoPhoto, 'item_page' => $aItem[$this->_oDb->_sFieldUri], 'item_title' => $aItem[$this->_oDb->_sFieldTitle]); } } } if ($iDeleted == count($aObjectIds)) { return array('perform_delete' => true); } if (empty($aOwner) || empty($aItems)) { return ""; } $aResult = array(); if ($bSave) { $aResult['save']['content'] = serialize($aContent); } $sCss = ""; if ($aEvent['js_mode']) { $sCss = $this->_oTemplate->addCss('wall_outline.css', true); } else { $this->_oTemplate->addCss('wall_outline.css'); } $iOwner = (int) $aEvent['owner_id']; $sOwner = getNickName($iOwner); $sOwnerLink = getProfileLink($iOwner); //--- Grouped events $iItems = count($aItems); if ($iItems > 1) { $sTmplName = isset($aParams['templates']['grouped']) ? $aParams['templates']['grouped'] : 'modules/boonex/wall/|outline_item_image_grouped'; $aResult['content'] = $sCss . $this->_oTemplate->parseHtmlByName($sTmplName, array('mod_prefix' => $this->_sPrefix, 'mod_icon' => $sIcon, 'user_name' => $sOwner, 'user_link' => $sOwnerLink, 'bx_repeat:items' => $aTmplItems, 'album_url' => '', 'album_title' => '', 'album_description' => '', 'album_comments' => 0 ? _t('_wall_n_comments', 0) : _t('_wall_no_comments'), 'album_comments_link' => '', 'post_id' => $aEvent['id'], 'post_ago' => $aEvent['ago'])); return $aResult; } //--- Single public event $aItem = $aItems[0]; $aTmplItem = $aTmplItems[0]; $sTmplName = isset($aParams['templates']['single']) ? $aParams['templates']['single'] : 'modules/boonex/wall/|outline_item_image'; $aResult['content'] = $sCss . $this->_oTemplate->parseHtmlByName($sTmplName, array_merge($aTmplItem, array('mod_prefix' => $this->_sPrefix, 'mod_icon' => $sIcon, 'user_name' => $sOwner, 'user_link' => $sOwnerLink, 'item_page' => $aItem[$this->_oDb->_sFieldUri], 'item_title' => $aItem[$this->_oDb->_sFieldTitle], 'item_description' => $this->_formatSnippetTextForOutline($aItem), 'item_comments' => (int) $aItem[$this->_oDb->_sFieldCommentCount] > 0 ? _t('_wall_n_comments', $aItem[$this->_oDb->_sFieldCommentCount]) : _t('_wall_no_comments'), 'item_comments_link' => $aItem[$this->_oDb->_sFieldUri] . '#cmta-' . $this->_sPrefix . '-' . $aItem[$this->_oDb->_sFieldId], 'post_id' => $aEvent['id'], 'post_ago' => $aEvent['ago']))); return $aResult; }
function grabImage($sInputFile, $sOutputFile, $sSize = "", $iSecond = 0, $bForse = false) { if (!$bForse && file_exists($sOutputFile) && filesize($sOutputFile) > 0) { return true; } bx_import('BxDolImageResize'); $oImage = BxDolImageResize::instance(); $bResult = true; $aSeconds = $iSecond != 0 ? array($iSecond) : array(0, 3, 5, 0); foreach ($aSeconds as $iSecond) { $bResult = convertVideoFile($sOutputFile, getGrabImageTmpl($sInputFile, $sOutputFile, $sSize, $iSecond)); if (!$bResult) { continue; } $aRgb = $oImage->getAverageColor($sOutputFile); $fRgb = ($aRgb['r'] + $aRgb['g'] + $aRgb['b']) / 3; if ($fRgb > 32 && $fRgb < 224) { break; } } return $bResult; }
protected function applyFilter_Grayscale($sFile, $aParams) { $o = BxDolImageResize::getInstance(); $o->removeCropOptions(); if (IMAGE_ERROR_SUCCESS == $o->grayscale($sFile)) { return true; } return false; }
/** * Applies watermark to image given in $srcFilename with specified opacity and saves result * to $dstFilename * * @param string $srcFilename - source image filename * @param string $dstFilename - destination image filename * @param string $wtrFilename - watermark filename * @param int $wtrTransparency - watermark transparency (from 0 to 100) * * @return int - zero on success, non-zero on fail * * * NOTE: Source image should be in GIF, JPEG or PNG format * NOTE: if $wtrTransparency = 0 then no action will be done with source image * but if $wtrTransparency = 100 then watermark will fully override source image */ function applyWatermark($srcFilename, $dstFilename, $wtrFilename, $wtrTransparency) { $o =& BxDolImageResize::instance(); return $o->applyWatermark($srcFilename, $dstFilename, $wtrFilename, $wtrTransparency); }
function setLogo(&$aData, &$aFile) { global $dir; $aFileInfo = getimagesize($aFile['new_file']['tmp_name']); if (empty($aFileInfo)) { return '_adm_txt_settings_file_not_image'; } $sExt = ''; switch ($aFileInfo['mime']) { case 'image/jpeg': $sExt = 'jpg'; break; case 'image/gif': $sExt = 'gif'; break; case 'image/png': $sExt = 'png'; break; } if (empty($sExt)) { return '_adm_txt_settings_file_wrong_format'; } $sFileName = mktime() . '.' . $sExt; $sFileName2x = BX_RETINA_PREFIX . mktime() . '.' . $sExt; $sFilePath = $dir['mediaImages'] . $sFileName; $sFilePath2x = $dir['mediaImages'] . $sFileName2x; if (!move_uploaded_file($aFile['new_file']['tmp_name'], $sFilePath)) { return '_adm_txt_settings_file_cannot_move'; } $o = BxDolImageResize::instance(); $o->removeCropOptions(); $o->setJpegOutput(false); $o->setSquareResize(false); if (!empty($aData['resize'])) { $iWidth = (int) $aData['new_width']; $iHeight = (int) $aData['new_height']; if ($iWidth <= 0 || $iHeight <= 0) { return '_adm_txt_settings_logo_wrong_size'; } $o->setSize($iWidth * 2, $iHeight * 2); if ($o->resize($sFilePath, $sFilePath2x) != IMAGE_ERROR_SUCCESS) { return '_adm_txt_settings_image_cannot_resize'; } $o->setSize($iWidth, $iHeight); if ($o->resize($sFilePath, $sFilePath) != IMAGE_ERROR_SUCCESS) { return '_adm_txt_settings_image_cannot_resize'; } } @unlink($dir['mediaImages'] . getParam('sys_main_logo')); @unlink($dir['mediaImages'] . BX_RETINA_PREFIX . getParam('sys_main_logo')); setParam('sys_main_logo', $sFileName); bx_import('BxDolImageResize'); $aFileNewSize = BxDolImageResize::getImageSize($sFilePath); setParam('sys_main_logo_w', $aFileNewSize['w']); setParam('sys_main_logo_h', $aFileNewSize['h']); return true; }
/** * Function export profile's avatar; * * @param : $iProfileId (integer); * @param : $sAvatarName (integer) - avatar's id; * @return : void; */ function _exportAvatar($iProfileId, $iAvatarId) { $iProfileId = (int) $iProfileId; $iAvatarId = (int) $iAvatarId; //define the old avatar's name; $sOldAvatarName = $this->getProfileImage($iAvatarId); if ($sOldAvatarName) { //define old avatar's path; $sOldAvatarPath = $this->oMigrationModule->_oDb->getExtraParam('config_profileImage') . $iProfileId . '/photo_' . $sOldAvatarName; require_once BX_DIRECTORY_PATH_MODULES . 'boonex/avatar/classes/BxAvaModule.php'; $oAvatar = BxDolModule::getInstance('BxAvaModule'); $oAvatar->_iProfileId = $iProfileId; // resize image; $sNewImagePath = BX_AVA_DIR_TMP . '_' . $iProfileId . BX_AVA_EXT; $o =& BxDolImageResize::instance(BX_AVA_W, BX_AVA_W); $o->removeCropOptions(); $o->setJpegOutput(true); $o->setSize(BX_AVA_W, BX_AVA_W); $o->setSquareResize(true); if (IMAGE_ERROR_SUCCESS != $o->resize($sOldAvatarPath, $sNewImagePath)) { return false; } return $oAvatar->_addAvatar($sNewImagePath, 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); }
function serviceGetWallPostOutline($aEvent) { $sPrefix = 'bx_' . $this->_oConfig->getUri(); $aProfile = getProfileInfo($aEvent['owner_id']); if (!$aProfile) { return ''; } $aObjectIds = strpos($aEvent['object_id'], ',') !== false ? explode(',', $aEvent['object_id']) : array($aEvent['object_id']); rsort($aObjectIds); $iItems = count($aObjectIds); $iItemsLimit = 3; if ($iItems > $iItemsLimit) { $aObjectIds = array_slice($aObjectIds, 0, $iItemsLimit); } $bSave = false; $aContent = array(); if (!empty($aEvent['content'])) { $aContent = unserialize($aEvent['content']); } if (!isset($aContent['idims'])) { $aContent['idims'] = array(); } $iDeleted = 0; $aItems = $aTmplItems = array(); foreach ($aObjectIds as $iId) { $aItem = $this->_oDb->getPostInfo($iId); if (empty($aItem)) { $iDeleted++; } else { if ($aItem['PostStatus'] == 'approval' && $this->oPrivacy->check('view', $aItem['PostID'], $this->_iVisitorID)) { $aItem['thumb_file'] = ''; $aItem['thumb_dims'] = array(); if (!empty($aItem['PostPhoto'])) { $aItem['thumb_file'] = BX_BLOGS_IMAGES_URL . 'browse_' . $aItem['PostPhoto']; $aItem['thumb_file_path'] = BX_BLOGS_IMAGES_PATH . 'browse_' . $aItem['PostPhoto']; if (!file_exists($aItem['thumb_file_path'])) { $aItem['thumb_file'] = BX_BLOGS_IMAGES_URL . 'big_' . $aItem['PostPhoto']; $aItem['thumb_file_path'] = BX_BLOGS_IMAGES_PATH . 'big_' . $aItem['PostPhoto']; } if (!isset($aContent['idims'][$iId])) { $sPath = file_exists($aItem['thumb_file_path']) ? $aItem['thumb_file_path'] : $aItem['thumb_file']; $aContent['idims'][$iId] = BxDolImageResize::instance()->getImageSize($sPath); $bSave = true; } $aItem['thumb_dims'] = $aContent['idims'][$iId]; $aItem['thumb_file_2x'] = BX_BLOGS_IMAGES_URL . 'orig_' . $aItem['PostPhoto']; $aItem['thumb_file_2x_path'] = BX_BLOGS_IMAGES_PATH . 'orig_' . $aItem['PostPhoto']; } $aItem['PostUrl'] = $this->genUrl($aItem['PostID'], $aItem['PostUri'], 'entry'); $aItems[] = $aItem; $aTmplItems[] = array('mod_prefix' => $sPrefix, 'item_width' => isset($aItem['thumb_dims']['w']) ? $aItem['thumb_dims']['w'] : $this->iThumbSize, 'item_height' => isset($aItem['thumb_dims']['h']) ? $aItem['thumb_dims']['h'] : $this->iThumbSize, 'item_icon' => $aItem['thumb_file'], 'item_icon_2x' => $aItem['thumb_file_2x'], 'item_page' => $aItem['PostUrl'], 'item_title' => $aItem['PostCaption'], 'item_description' => strmaxtextlen($aItem['PostText'], 300)); } } } if ($iDeleted == count($aObjectIds)) { return array('perform_delete' => true); } if (empty($aItems)) { return ''; } $aResult = array(); if ($bSave) { $aResult['save']['content'] = serialize($aContent); } $sCss = ''; if ($aEvent['js_mode']) { $sCss = $this->_oTemplate->addCss(array('wall_outline.css'), true); } else { $this->_oTemplate->addCss(array('wall_outline.css')); } $iItems = count($aItems); $iOwner = (int) $aEvent['owner_id']; $sOwner = getNickName($iOwner); $sOwnerLink = getProfileLink($iOwner); //--- Grouped events $iItems = count($aItems); if ($iItems > 1) { $sTmplName = 'wall_outline_grouped.html'; $aResult['content'] = $sCss . $this->_oTemplate->parseHtmlByName($sTmplName, array('mod_prefix' => $sPrefix, 'mod_icon' => 'book', 'user_name' => $sOwner, 'user_link' => $sOwnerLink, 'bx_repeat:items' => $aTmplItems, 'item_comments' => 0 ? _t('_wall_n_comments', 0) : _t('_wall_no_comments'), 'item_comments_link' => '', 'post_id' => $aEvent['id'], 'post_ago' => $aEvent['ago'])); return $aResult; } //--- Single public event $aItem = $aItems[0]; $aTmplItem = $aTmplItems[0]; $sTmplName = empty($aItem['thumb_file']) ? 'modules/boonex/wall/|outline_item_text.html' : 'modules/boonex/wall/|outline_item_image.html'; $aResult['content'] = $sCss . $this->_oTemplate->parseHtmlByName($sTmplName, array_merge($aTmplItem, array('mod_prefix' => $sPrefix, 'mod_icon' => 'book', 'user_name' => $sOwner, 'user_link' => $sOwnerLink, 'item_comments' => (int) $aItem['CommentsCount'] > 0 ? _t('_wall_n_comments', $aItem['CommentsCount']) : _t('_wall_no_comments'), 'item_comments_link' => $aItem['PostUrl'] . '#cmta-' . $sPrefix . '-' . $aItem['PostID'], 'post_id' => $aEvent['id'], 'post_ago' => $aEvent['ago']))); return $aResult; }
/** * 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); }
function _cropAvatar() { $sSrcImagePath = BX_AVA_DIR_TMP . $this->_iProfileId . BX_AVA_EXT; $sDstImagePath = BX_AVA_DIR_TMP . 'tmp' . $this->_iProfileId . BX_AVA_EXT; $o =& BxDolImageResize::instance(); $o->setJpegOutput(true); $o->setSize(BX_AVA_W, BX_AVA_H); $o->setJpegQuality(getParam('bx_avatar_quality')); if ((int) $_POST['w'] && (int) $_POST['h']) { $o->setCropOptions((int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['w'], (int) $_POST['h']); $o->setSquareResize(false); } else { $o->setSquareResize(true); } if (IMAGE_ERROR_SUCCESS == $o->resize($sSrcImagePath, $sDstImagePath) && $this->_addAvatar($sDstImagePath, true)) { @unlink($sSrcImagePath); return true; } @unlink($sDstImagePath); return false; }
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; }