public function cropAlbumCover(PHOTO_BOL_PhotoAlbum $album, $coords, $viewSize, $photoId = 0) { if (!empty($photoId) && ($photo = $this->photoDao->findById($photoId)) !== NULL) { $path = $this->photoDao->getPhotoPath($photo->id, $photo->hash, 'main'); } else { $path = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathByAlbumId($album->id); } $storage = OW::getStorage(); $tmpPath = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(time(), TRUE) . '.jpg'; $storage->copyFileToLocalFS($path, $tmpPath); if (($coverDto = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->findByAlbumId($album->id)) === NULL) { $coverDto = new PHOTO_BOL_PhotoAlbumCover(); $coverDto->albumId = $album->id; PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->save($coverDto); } $oldCover = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathForCoverEntity($coverDto); $oldCoverOrig = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigPathForCoverEntity($coverDto); $coverDto->hash = uniqid(); $coverDto->auto = 0; try { $image = new UTIL_Image($tmpPath); if ($image->getWidth() >= $coords['w'] && $coords['w'] > 0 && $image->getHeight() >= $coords['h'] && $coords['h'] > 0) { $width = $image->getWidth(); $k = $width / $viewSize; $image->cropImage($coords['x'] * $k, $coords['y'] * $k, $coords['w'] * $k, $coords['h'] * $k); } $saveImage = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(time(), TRUE) . '.jpg'; $image->saveImage($saveImage); $image->destroy(); $storage->copyFile($saveImage, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathForCoverEntity($coverDto)); $storage->copyFile($tmpPath, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigPathForCoverEntity($coverDto)); $storage->removeFile($oldCover); $storage->removeFile($oldCoverOrig); @unlink($saveImage); @unlink($tmpPath); PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->save($coverDto); } catch (Exception $e) { return FALSE; } return array('cover' => PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverUrlForCoverEntity($coverDto), 'coverOrig' => PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigUrlForCoverEntity($coverDto)); }
/** * Get path to photo in file system * * @param int $photoId * @param $hash * @param string $type * @return string */ public function getPhotoPath($photoId, $hash, $type = '') { return $this->photoDao->getPhotoPath($photoId, $hash, $type); }