/** * 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); } }
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); } }
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); } }
public function uploadImage($dir, $width, $height) { $imgmanager = new ImageManager(); $imgmanager->createImageFromFile($this->data->tmpDir, $this->data->name); $imgmanager->resizeImage($width, $height, null); if (!file_exists($dir)) { mkdir($dir, 0777, true); } $dir = $dir . $this->data->name; $imgmanager->saveImage('png', $dir); $this->img64 = $imgmanager->getImageBase64(); //$this->moveFileToServer(); $this->saveLoginImageInDB($dir); }