public function cropTempAvatar($key, $coords, $viewSize)
 {
     $originalPath = $this->getTempAvatarPath($key, 3);
     $bigAvatarPath = $this->getTempAvatarPath($key, 2);
     $avatarPath = $this->getTempAvatarPath($key, 1);
     $image = new UTIL_Image($originalPath);
     $width = $image->getWidth();
     $k = $width / $viewSize;
     $config = OW::getConfig();
     $avatarSize = (int) $config->getValue('base', 'avatar_size');
     $bigAvatarSize = (int) $config->getValue('base', 'avatar_big_size');
     $image->cropImage($coords['x'] * $k, $coords['y'] * $k, $coords['w'] * $k, $coords['h'] * $k)->resizeImage($bigAvatarSize, $bigAvatarSize, true)->saveImage($bigAvatarPath)->resizeImage($avatarSize, $avatarSize, true)->saveImage($avatarPath);
     return true;
 }
Exemple #2
0
 /**
  * Crops user avatar using coordinates
  *
  * @param int $userId
  * @param array $coords
  * @param int $viewSize
  * @param int $hash
  */
 public function cropAvatar($userId, $coords, $viewSize, $hash)
 {
     if (!empty($coords)) {
         $origAvatarPath = $this->getAvatarPath($userId, 3);
         // tmp file in pluginfiles
         $tmpPath = $this->getAvatarPluginFilesPath($userId, 3, $hash);
         $storage = OW::getStorage();
         $storage->copyFileToLocalFS($origAvatarPath, $tmpPath);
         $image = new UTIL_Image($tmpPath);
         $width = $image->getWidth();
         $height = $image->getHeight();
         $k = $width / $viewSize;
         $config = OW::getConfig();
         $avatarSize = (int) $config->getValue('base', 'avatar_size');
         $bigAvatarSize = (int) $config->getValue('base', 'avatar_big_size');
         $avatarPath = $this->getAvatarPath($userId, 1, $hash);
         $bigAvatarPath = trim($this->getAvatarPath($userId, 2, $hash));
         // pluginfiles tmp path
         $avatarPFPath = $this->getAvatarPluginFilesPath($userId, 1, $hash);
         $bigAvatarPFPath = trim($this->getAvatarPluginFilesPath($userId, 2, $hash));
         $image->cropImage($coords['x'] * $k, $coords['y'] * $k, $coords['w'] * $k, $coords['h'] * $k)->resizeImage($bigAvatarSize, $bigAvatarSize, true)->saveImage($bigAvatarPFPath)->resizeImage($avatarSize, $avatarSize, true)->saveImage($avatarPFPath);
         $storage->copyFile($bigAvatarPFPath, $bigAvatarPath);
         $storage->copyFile($avatarPFPath, $avatarPath);
         @unlink($tmpPath);
         @unlink($avatarPFPath);
         @unlink($bigAvatarPFPath);
     }
 }
 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));
 }
Exemple #4
0
 public function createAlbumCover($albumId, array $photos)
 {
     if (empty($albumId) || count($photos) === 0 || PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->isAlbumCoverExist($albumId)) {
         return FALSE;
     }
     foreach ($photos as $photo) {
         $path = $this->getPhotoPath($photo->id, $photo->hash, 'main');
         $storage = OW::getStorage();
         if (!$storage->fileExists($path)) {
             continue;
         }
         $tmpPathCrop = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(uniqid(), TRUE) . '.jpg';
         $tmpPathOrig = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(uniqid(), TRUE) . '.jpg';
         if (!$storage->copyFileToLocalFS($path, $tmpPathOrig)) {
             continue;
         }
         $info = getimagesize($tmpPathOrig);
         if ($info['0'] < 330 || $info['1'] < 330) {
             @unlink($tmpPathOrig);
             continue;
         }
         $coverDto = new PHOTO_BOL_PhotoAlbumCover();
         $coverDto->albumId = $albumId;
         $coverDto->hash = uniqid();
         PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->save($coverDto);
         $image = new UTIL_Image($tmpPathOrig);
         $left = $image->getWidth() / 2 - 165;
         $top = $image->getHeight() / 2 - 165;
         $image->cropImage($left, $top, 330, 330);
         $image->saveImage($tmpPathCrop);
         $image->destroy();
         $storage->copyFile($tmpPathCrop, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathForCoverEntity($coverDto));
         $storage->copyFile($tmpPathOrig, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigPathForCoverEntity($coverDto));
         @unlink($tmpPathCrop);
         @unlink($tmpPathOrig);
         return TRUE;
     }
     return FALSE;
 }