Beispiel #1
0
 /**
  * Creates a thumbnail of a picture
  *
  * Note that all "Path" parameters are required to bring along their
  * own trailing slash.
  * 
  * @param   string  $strPath
  * @param   string  $strWebPath
  * @param   string  $file
  * @param   int     $maxSize      The maximum width or height of the image
  * @param   int     $quality
  * @return  boolean
  */
 function _createThumb($strPath, $strWebPath, $file, $maxSize = 80, $quality = 90, $thumb_name = '', $generateThumbnailByRatio = false)
 {
     $_objImage = new ImageManager();
     $file = basename($file);
     $tmpSize = getimagesize($strPath . $file);
     $factor = 1;
     if ($tmpSize[0] > $tmpSize[1]) {
         $factor = $maxSize / $tmpSize[0];
     } else {
         $factor = $maxSize / $tmpSize[1];
     }
     $thumbWidth = $tmpSize[0] * $factor;
     $thumbHeight = $tmpSize[1] * $factor;
     if (!$_objImage->loadImage($strPath . $file)) {
         return false;
     }
     if ($generateThumbnailByRatio && !$_objImage->resizeImageWithAspectRatio($thumbWidth, $thumbHeight, $quality)) {
         return false;
     } elseif (!$generateThumbnailByRatio && !$_objImage->resizeImage($thumbWidth, $thumbHeight, $quality)) {
         return false;
     }
     if (!(strlen($thumb_name) > 0)) {
         $thumb_name = self::getThumbnailFilename($file);
     }
     if (!$_objImage->saveNewImage($strPath . $thumb_name)) {
         return false;
     }
     if (!\Cx\Lib\FileSystem\FileSystem::makeWritable($strPath . $thumb_name)) {
         return false;
     }
     return true;
 }
 /**
  * Move uploaded image into respective folder
  *
  * @param Object  $objUser
  * @param String  $tmpImageName
  * @param String  $name
  * @param Boolean $profilePic
  *
  * @return String
  */
 protected static function moveUploadedImageInToPlace($objUser, $tmpImageName, $name, $profilePic = false)
 {
     static $objImage, $arrSettings;
     if (empty($objImage)) {
         $objImage = new \ImageManager();
     }
     if (empty($arrSettings)) {
         $arrSettings = array();
         $arrSettings['profile_thumbnail_pic_width']['value'] = 80;
         $arrSettings['profile_thumbnail_pic_height']['value'] = 60;
         $arrSettings['profile_thumbnail_scale_color']['value'] = '';
         $arrSettings['profile_thumbnail_method']['value'] = '';
         $arrSettings['max_profile_pic_width']['value'] = 160;
         $arrSettings['max_profile_pic_height']['value'] = 160;
     }
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $imageRepo = $profilePic ? $cx->getWebsiteImagesAccessProfilePath() : $cx->getWebsiteImagesAccessPhotoPath();
     $index = 0;
     $imageName = $objUser->getId() . '_' . $name;
     while (file_exists($imageRepo . '/' . $imageName)) {
         $imageName = $objUser->getId() . '_' . ++$index . '_' . $name;
     }
     if (!$objImage->loadImage($tmpImageName)) {
         return false;
     }
     // resize image if its dimensions are greater than allowed
     if ($objImage->orgImageWidth > $arrSettings['max_profile_pic_width']['value'] || $objImage->orgImageHeight > $arrSettings['max_profile_pic_height']['value']) {
         $ratioWidth = $arrSettings['max_profile_pic_width']['value'] / $objImage->orgImageWidth;
         $ratioHeight = $arrSettings['max_profile_pic_height']['value'] / $objImage->orgImageHeight;
         if ($ratioHeight > $ratioWidth) {
             $newWidth = $objImage->orgImageWidth * $ratioWidth;
             $newHeight = $objImage->orgImageHeight * $ratioWidth;
         } else {
             $newWidth = $objImage->orgImageWidth * $ratioHeight;
             $newHeight = $objImage->orgImageHeight * $ratioHeight;
         }
         if (!$objImage->resizeImage($newWidth, $newHeight, 100)) {
             return false;
         }
         // copy image to the image repository
         if (!$objImage->saveNewImage($imageRepo . '/' . $imageName)) {
             return false;
         }
     } else {
         if (!copy($tmpImageName, $imageRepo . '/' . $imageName)) {
             return false;
         }
     }
     return $imageName;
 }
 function createThumbnail($strPathImage)
 {
     $arrImageInfo = getimagesize(\Env::get('cx')->getWebsitePath() . $strPathImage);
     if ($arrImageInfo['mime'] == "image/gif" || $arrImageInfo['mime'] == "image/jpeg" || $arrImageInfo['mime'] == "image/jpg" || $arrImageInfo['mime'] == "image/png") {
         $objImage = new \ImageManager();
         $arrImageInfo = array_merge($arrImageInfo, pathinfo($strPathImage));
         $thumbWidth = intval($this->arrSettings['settingsThumbSize']);
         $thumbHeight = intval($thumbWidth / $arrImageInfo[0] * $arrImageInfo[1]);
         $objImage->loadImage(\Env::get('cx')->getWebsitePath() . $strPathImage);
         $objImage->resizeImage($thumbWidth, $thumbHeight, 100);
         $objImage->saveNewImage(\Env::get('cx')->getWebsitePath() . $strPathImage . '.thumb', true);
     }
 }
Beispiel #4
0
 private function createThumbnailOfImage($imageName, $profilePic = false)
 {
     static $objImage, $arrSettings;
     if (empty($objImage)) {
         $objImage = new \ImageManager();
     }
     if (empty($arrSettings)) {
         $arrSettings = \User_Setting::getSettings();
     }
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     if ($profilePic) {
         if (!$objImage->loadImage($cx->getWebsiteImagesAccessProfilePath() . '/' . $imageName)) {
             return false;
         }
         $rationWidth = $objImage->orgImageWidth / $arrSettings['profile_thumbnail_pic_width']['value'];
         $rationHeight = $objImage->orgImageHeight / $arrSettings['profile_thumbnail_pic_height']['value'];
         if ($arrSettings['profile_thumbnail_method']['value'] == 'crop') {
             if ($rationWidth < $rationHeight) {
                 $objImage->orgImageHeight = $objImage->orgImageHeight / $rationHeight * $rationWidth;
             } else {
                 $objImage->orgImageWidth = $objImage->orgImageWidth / $rationWidth * $rationHeight;
             }
             if (!$objImage->resizeImage($arrSettings['profile_thumbnail_pic_width']['value'], $arrSettings['profile_thumbnail_pic_height']['value'], 70)) {
                 return false;
             }
         } else {
             $ration = max($rationWidth, $rationHeight);
             $objImage->addBackgroundLayer(sscanf($arrSettings['profile_thumbnail_scale_color']['value'], '#%2X%2x%2x'), $arrSettings['profile_thumbnail_pic_width']['value'], $arrSettings['profile_thumbnail_pic_height']['value']);
         }
         $thumb_name = \ImageManager::getThumbnailFilename($cx->getWebsiteImagesAccessProfilePath() . '/' . $imageName);
         return $objImage->saveNewImage($thumb_name, true);
     } else {
         $thumb_name = \ImageManager::getThumbnailFilename($imageName);
         return $objImage->_createThumbWhq($cx->getWebsiteImagesAccessPhotoPath() . '/', $cx->getWebsiteImagesAccessPhotoWebPath() . '/', $imageName, $arrSettings['max_thumbnail_pic_width']['value'], $arrSettings['max_thumbnail_pic_height']['value'], 70, '', $cx->getWebsiteImagesAccessPhotoPath() . '/', $cx->getWebsiteImagesAccessPhotoWebPath() . '/', basename($cx->getWebsiteImagesAccessProfilePath() . '/' . $thumb_name));
     }
 }
 function _createThumbnail($file, $overwrite = false)
 {
     global $_ARRAYLANG;
     $tmpSize = getimagesize($file);
     $thumbWidth = $this->thumbHeight / $tmpSize[1] * $tmpSize[0];
     $thumb_name = \ImageManager::getThumbnailFilename($file);
     $tmp = new \ImageManager();
     $tmp->loadImage($file);
     $tmp->resizeImage($thumbWidth, $this->thumbHeight, $this->thumbQuality);
     $tmp->saveNewImage($thumb_name, $overwrite);
     if (!file_exists($thumb_name)) {
         $img = imagecreate(100, 50);
         $colBody = imagecolorallocate($img, 255, 255, 255);
         ImageFilledRectangle($img, 0, 0, 100, 50, $colBody);
         $colFont = imagecolorallocate($img, 0, 0, 0);
         imagettftext($img, 10, 0, 18, 29, $colFont, self::_getIconPath() . 'arial.ttf', 'no preview');
         imagerectangle($img, 0, 0, 99, 49, $colFont);
         imagejpeg($img, $thumb_name, $this->thumbQuality);
     }
 }
 /**
  * Rotates an image clockwise by 90�
  *
  * @global    ADONewConnection
  * @global    array
  * @global    array
  */
 function rotatePicture($intImageId)
 {
     global $objDatabase, $_ARRAYLANG, $_CONFIG;
     if (!function_exists('imagerotate')) {
         $this->strErrMessage = $_ARRAYLANG['TXT_GALLERY_GD_LIB_NOT_INSTALLED'];
         return false;
     }
     $objResult = $objDatabase->Execute('SELECT     path,
                                                 quality,
                                                 size_type,
                                                 size_proz,
                                                 size_abs_h,
                                                 size_abs_w
                                         FROM     ' . DBPREFIX . 'module_gallery_pictures
                                         WHERE     id=' . $intImageId);
     $strImagename = $objResult->fields['path'];
     $strOrgPath = $this->strImagePath;
     $strWebpath = $this->strImageWebPath;
     $strThumbPath = $this->strThumbnailPath;
     $strThumbWebpath = $this->strThumbnailWebPath;
     $objImage = new \ImageManager();
     $objImage->loadImage($strOrgPath . $strImagename);
     //Rotate the clockwise
     if ($objImage->rotateImage(270)) {
         //To save the Rotated image
         if ($objImage->saveNewImage($strOrgPath . $strImagename, true)) {
             \Cx\Lib\FileSystem\FileSystem::delete_file($strThumbPath . $strImagename);
         }
         $imageSize = $objImage->_getImageSize($strOrgPath . $strImagename);
         $intOldWidth = $imageSize[0];
         $intOldHeight = $imageSize[1];
         if ($objResult->fields['size_type'] == 'abs') {
             $intNewWidth = intval($this->arrSettings['standard_width_abs']);
             $intNewHeight = intval($this->arrSettings['standard_height_abs']);
             if ($intNewWidth == 0) {
                 // exception if width and height or 0!
                 if ($intNewHeight == 0) {
                     $intNewHeight = 100;
                 }
                 $intNewWidth = round($intOldWidth * $intNewHeight / $intOldHeight, 0);
             } else {
                 if ($intNewHeight == 0) {
                     $intNewHeight = round($intOldHeight * $intNewWidth / $intOldWidth, 0);
                 }
             }
         } else {
             $intNewWidth = round($objResult->fields['size_proz'] / 100 * $intOldWidth, 0);
             $intNewHeight = round($objResult->fields['size_proz'] / 100 * $intOldHeight, 0);
         }
         //Resize the Rotated image
         if ($objImage->resizeImageSave($strOrgPath, $strWebpath, $strImagename, $intNewWidth, $intNewHeight, $objResult->fields['quality'], $strThumbPath, $strThumbWebpath, $strImagename)) {
             if ($objResult->fields['size_type'] == 'abs') {
                 $objDatabase->Execute('    UPDATE     ' . DBPREFIX . 'module_gallery_pictures
                                 SET     size_abs_h=' . $intNewHeight . ',
                                         size_abs_w=' . $intNewWidth . '
                                 WHERE     id=' . $intImageId);
             }
         }
     }
 }
 private function createThumbnailOfImage($imageName, $profilePic = false)
 {
     static $objImage, $arrSettings;
     if (empty($objImage)) {
         $objImage = new \ImageManager();
     }
     if (empty($arrSettings)) {
         $arrSettings = \User_Setting::getSettings();
     }
     if ($profilePic) {
         if (!$objImage->loadImage(ASCMS_ACCESS_PROFILE_IMG_PATH . '/' . $imageName)) {
             return false;
         }
         $rationWidth = $objImage->orgImageWidth / $arrSettings['profile_thumbnail_pic_width']['value'];
         $rationHeight = $objImage->orgImageHeight / $arrSettings['profile_thumbnail_pic_height']['value'];
         if ($arrSettings['profile_thumbnail_method']['value'] == 'crop') {
             if ($rationWidth < $rationHeight) {
                 $objImage->orgImageHeight = $objImage->orgImageHeight / $rationHeight * $rationWidth;
             } else {
                 $objImage->orgImageWidth = $objImage->orgImageWidth / $rationWidth * $rationHeight;
             }
             if (!$objImage->resizeImage($arrSettings['profile_thumbnail_pic_width']['value'], $arrSettings['profile_thumbnail_pic_height']['value'], 70)) {
                 return false;
             }
         } else {
             $ration = max($rationWidth, $rationHeight);
             $objImage->addBackgroundLayer(sscanf($arrSettings['profile_thumbnail_scale_color']['value'], '#%2X%2x%2x'), $arrSettings['profile_thumbnail_pic_width']['value'], $arrSettings['profile_thumbnail_pic_height']['value']);
         }
         $thumb_name = \ImageManager::getThumbnailFilename($imageName);
         return $objImage->saveNewImage(ASCMS_ACCESS_PROFILE_IMG_PATH . '/' . $thumb_name);
     } else {
         return $objImage->_createThumbWhq(ASCMS_ACCESS_PHOTO_IMG_PATH . '/', ASCMS_ACCESS_PHOTO_IMG_WEB_PATH . '/', $imageName, $arrSettings['max_thumbnail_pic_width']['value'], $arrSettings['max_thumbnail_pic_height']['value'], 70);
     }
 }