public function addTemporaryPhoto($source, $userId, $order) { if (!file_exists($source) || !$userId) { return false; } $tmpPhoto = new PHOTO_BOL_PhotoTemporary(); $tmpPhoto->userId = $userId; $tmpPhoto->addDatetime = time(); $tmpPhoto->hasFullsize = 0; $tmpPhoto->order = $order; $this->photoTemporaryDao->save($tmpPhoto); $preview = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 1); $main = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 2); $original = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 3); $config = OW::getConfig(); $width = $config->getValue('photo', 'main_image_width'); $height = $config->getValue('photo', 'main_image_height'); $previewWidth = $config->getValue('photo', 'preview_image_width'); $previewHeight = $config->getValue('photo', 'preview_image_height'); try { $image = new UTIL_Image($source); $mainPhoto = $image->resizeImage($width, $height)->orientateImage()->saveImage($main); if ((bool) $config->getValue('photo', 'store_fullsize') && $mainPhoto->imageResized()) { $originalImage = new UTIL_Image($source); $res = (int) $config->getValue('photo', 'fullsize_resolution'); $res = $res ? $res : 1024; $originalImage->resizeImage($res, $res)->orientateImage()->saveImage($original); $tmpPhoto->hasFullsize = 1; $this->photoTemporaryDao->save($tmpPhoto); } $mainPhoto->resizeImage($previewWidth, $previewHeight, true)->orientateImage()->saveImage($preview); } catch (WideImage_Exception $e) { $this->photoTemporaryDao->deleteById($tmpPhoto->id); return false; } return $tmpPhoto->id; }
public function addTemporaryPhoto($source, $userId, $order = 0) { if (!file_exists($source) || !$userId) { return FALSE; } $tmpPhoto = new PHOTO_BOL_PhotoTemporary(); $tmpPhoto->userId = $userId; $tmpPhoto->addDatetime = time(); $tmpPhoto->hasFullsize = 0; $tmpPhoto->order = $order; $this->photoTemporaryDao->save($tmpPhoto); try { /* * Beter performance but less quolity - small size images is slightly clouded * $fullscreenTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 5); $originalTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 3); $mainTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 2); $previewTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 1); $smallTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 4); $image = new UTIL_Image($source); $storeFullSize = OW::getConfig()->getValue('photo', 'store_fullsize'); if ( $storeFullSize ) { $image->resizeImage(PHOTO_BOL_PhotoService::DIM_FULLSCREEN_WIDTH, PHOTO_BOL_PhotoService::DIM_FULLSCREEN_HEIGHT) ->orientateImage() ->saveImage($fullscreenTmp); $tmpPhoto->hasFullsize = 1; } $image->resizeImage(PHOTO_BOL_PhotoService::DIM_ORIGINAL_WIDTH, PHOTO_BOL_PhotoService::DIM_ORIGINAL_HEIGHT); if ( !$storeFullSize ) { $image->orientateImage(); } $image->saveImage($originalTmp) ->resizeImage(PHOTO_BOL_PhotoService::DIM_MAIN_WIDTH, PHOTO_BOL_PhotoService::DIM_MAIN_HEIGHT) ->saveImage($mainTmp) ->resizeImage(PHOTO_BOL_PhotoService::DIM_PREVIEW_WIDTH, PHOTO_BOL_PhotoService::DIM_PREVIEW_HEIGHT) ->saveImage($previewTmp) ->resizeImage(PHOTO_BOL_PhotoService::DIM_SMALL_WIDTH, PHOTO_BOL_PhotoService::DIM_SMALL_HEIGHT, TRUE) ->saveImage($smallTmp) ->destroy(); $this->photoTemporaryDao->save($tmpPhoto); */ $smallTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 4); $smallImg = new UTIL_Image($source); $smallImg->resizeImage(PHOTO_BOL_PhotoService::DIM_SMALL_WIDTH, PHOTO_BOL_PhotoService::DIM_SMALL_HEIGHT, TRUE)->orientateImage()->saveImage($smallTmp)->destroy(); $previewTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 1); $previewImage = new UTIL_Image($source); $previewImage->resizeImage(PHOTO_BOL_PhotoService::DIM_PREVIEW_WIDTH, PHOTO_BOL_PhotoService::DIM_PREVIEW_HEIGHT)->orientateImage()->saveImage($previewTmp)->destroy(); $mainTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 2); $main = new UTIL_Image($source); $mainImage = $main->resizeImage(PHOTO_BOL_PhotoService::DIM_MAIN_WIDTH, PHOTO_BOL_PhotoService::DIM_MAIN_HEIGHT)->orientateImage()->saveImage($mainTmp); $mainImageResized = $mainImage->imageResized(); $mainImage->destroy(); $originalTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 3); $originalImage = new UTIL_Image($source); $originalImage->resizeImage(PHOTO_BOL_PhotoService::DIM_ORIGINAL_WIDTH, PHOTO_BOL_PhotoService::DIM_ORIGINAL_HEIGHT)->orientateImage()->saveImage($originalTmp)->destroy(); if ($mainImageResized && (bool) OW::getConfig()->getValue('photo', 'store_fullsize')) { $fullscreenTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 5); $fullscreen = new UTIL_Image($source); $fullscreen->resizeImage(PHOTO_BOL_PhotoService::DIM_FULLSCREEN_WIDTH, PHOTO_BOL_PhotoService::DIM_FULLSCREEN_HEIGHT)->orientateImage()->saveImage($fullscreenTmp)->destroy(); $tmpPhoto->hasFullsize = 1; } $this->photoTemporaryDao->save($tmpPhoto); } catch (WideImage_Exception $e) { $this->photoTemporaryDao->deleteById($tmpPhoto->id); return FALSE; } return $tmpPhoto->id; }