本文整理汇总了PHP中JImage::resize方法的典型用法代码示例。如果您正苦于以下问题:PHP JImage::resize方法的具体用法?PHP JImage::resize怎么用?PHP JImage::resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JImage
的用法示例。
在下文中一共展示了JImage::resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create()
{
$output = '';
$size = JRequest::getCmd('size', '');
if (!in_array($size, array('min', 'medium'))) {
throw new Exception('The image size is not recognized', 500);
}
$image = JRequest::getVar('image', '');
$id = JRequest::getInt('id', 0);
$imagePath = JPATH_ROOT . DS . 'images' . DS . 'com_jea' . DS . 'images' . DS . $id . DS . $image;
$thumbDir = JPATH_ROOT . DS . 'images' . DS . 'com_jea' . DS . 'thumb-' . $size;
$thumbPath = $thumbDir . DS . $id . '-' . $image;
if (file_exists($thumbPath)) {
$output = readfile($thumbPath);
} elseif (file_exists($imagePath)) {
if (!JFolder::exists($thumbPath)) {
JFolder::create($thumbDir);
}
$params = JComponentHelper::getParams('com_jea');
if ($size == 'medium') {
$width = $params->get('thumb_medium_width', 400);
$height = $params->get('thumb_medium_height', 300);
} else {
$width = $params->get('thumb_min_width', 120);
$height = $params->get('thumb_min_height', 90);
}
$quality = (int) $params->get('jpg_quality', 90);
$cropThumbnails = (bool) $params->get('crop_thumbnails', 0);
$JImage = new JImage($imagePath);
if ($cropThumbnails) {
$thumb = $JImage->resize($width, $height, true, JImage::SCALE_OUTSIDE);
$left = $thumb->getWidth() > $width ? intval(($thumb->getWidth() - $width) / 2) : 0;
$top = $thumb->getHeight() > $height ? intval(($thumb->getHeight() - $height) / 2) : 0;
$thumb->crop($width, $height, $left, $top, false);
} else {
$thumb = $JImage->resize($width, $height);
}
$thumb->toFile($thumbPath, IMAGETYPE_JPEG, array('quality' => $quality));
$output = readfile($thumbPath);
} else {
throw new Exception('The image ' . $image . ' was not found', 500);
}
JResponse::setHeader('Content-Type', 'image/jpeg', true);
JResponse::setHeader('Content-Transfer-Encoding', 'binary');
JResponse::allowCache(false);
JResponse::setBody($output);
echo JResponse::toString();
exit;
}
示例2: createThumb
public static function createThumb($path, $width = 100, $height = 100, $crop = 2)
{
$myImage = new JImage();
$myImage->loadFile(JPATH_SITE . DS . $path);
if ($myImage->isLoaded()) {
// $filename = end(explode('/', $path));
$filename = JFile::getName($path);
$filefolder = substr(md5(self::getFolderPath($path)), 1, 10);
$newfilename = $width . 'x' . $height . '_' . $filefolder . '_' . JFile::makeSafe($filename);
$fileExists = JFile::exists(JPATH_CACHE . '/' . $newfilename);
if (!$fileExists) {
$resizedImage = $myImage->resize($width, $height, true, $crop);
$properties = $myImage->getImageFileProperties($path);
$mime = $properties->mime;
if ($mime == 'image/jpeg') {
$type = IMAGETYPE_JPEG;
} elseif ($mime = 'image/png') {
$type = IMAGETYPE_PNG;
} elseif ($mime = 'image/gif') {
$type = IMAGETYPE_GIF;
}
$resizedImage->toFile(JPATH_CACHE . '/' . $newfilename, $type);
}
return $newfilename;
} else {
return "My file is not loaded";
}
}
示例3: createThumbnail
/**
* Create a thumbnail from an image file.
*
* <code>
* $myFile = "/tmp/myfile.jpg";
*
* $options = array(
* "destination" => "image/mypic.jpg",
* "width" => 200,
* "height" => 200,
* "scale" => JImage::SCALE_INSIDE
* );
*
* $file = new PrismFileImage($myFile);
* $file->createThumbnail($options);
*
* </code>
*
* @param array $options Some options used in the process of generating thumbnail.
*
* @throws \InvalidArgumentException
* @throws \RuntimeException
*
* @return string A location to the new file.
*/
public function createThumbnail($options)
{
$width = ArrayHelper::getValue($options, "width", 100);
$height = ArrayHelper::getValue($options, "height", 100);
$scale = ArrayHelper::getValue($options, "scale", \JImage::SCALE_INSIDE);
$destination = ArrayHelper::getValue($options, "destination");
if (!$destination) {
throw new \InvalidArgumentException(\JText::_("LIB_PRISM_ERROR_INVALID_FILE_DESTINATION"));
}
// Generate thumbnail.
$image = new \JImage();
$image->loadFile($this->file);
if (!$image->isLoaded()) {
throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND', $this->file));
}
// Resize the file as a new object
$thumb = $image->resize($width, $height, true, $scale);
$fileName = basename($this->file);
$ext = \JString::strtolower(\JFile::getExt(\JFile::makeSafe($fileName)));
switch ($ext) {
case "gif":
$type = IMAGETYPE_GIF;
break;
case "png":
$type = IMAGETYPE_PNG;
break;
case IMAGETYPE_JPEG:
default:
$type = IMAGETYPE_JPEG;
}
$thumb->toFile($destination, $type);
return $destination;
}
示例4: createThumb
public static function createThumb($path, $width = 100, $height = 100, $crop = 2, $cachefolder = 'hgimages', $external = 0)
{
$myImage = new JImage();
if (!$external) {
$myImage->loadFile(JPATH_SITE . DS . $path);
} else {
$myImage->loadFile($path);
}
if ($myImage->isLoaded()) {
// $filename = end(explode('/', $path));
$filename = JFile::getName($path);
$filefolder = substr(md5(self::getFolderPath($path)), 1, 10);
$newfilename = $width . 'x' . $height . 'x' . $crop . '_' . $filefolder . '_' . JFile::makeSafe($filename);
$hgimages = JPATH_CACHE . '/' . $cachefolder . '/';
if (!JFolder::exists($hgimages)) {
JFolder::create($hgimages);
}
$fileExists = JFile::exists($hgimages . $newfilename);
if (!$fileExists) {
switch ($crop) {
// Case for self::CROP
case 4:
$resizedImage = $myImage->crop($width, $height, null, null, true);
break;
// Case for self::CROP_RESIZE
// Case for self::CROP_RESIZE
case 5:
$resizedImage = $myImage->cropResize($width, $height, true);
break;
default:
$resizedImage = $myImage->resize($width, $height, true, $crop);
break;
}
$properties = $myImage->getImageFileProperties($path);
$mime = $properties->mime;
if ($mime == 'image/jpeg') {
$type = IMAGETYPE_JPEG;
} elseif ($mime = 'image/png') {
$type = IMAGETYPE_PNG;
} elseif ($mime = 'image/gif') {
$type = IMAGETYPE_GIF;
}
$resizedImage->toFile($hgimages . $newfilename, $type);
}
return $newfilename;
} else {
return "My file is not loaded";
}
}
示例5: resize
public function resize($type, $width, $height, $crop = false)
{
if ($type == 'thumbnail') {
$path = $this->gallery->getThumbnailsPath();
$filePath =& $this->thumbnailFilepath;
$scale = 3;
// SCALE_OUTSIDE
$options = array('quality' => 75);
// TODO as param
} else {
if ($type == 'resized') {
$path = $this->gallery->getResizedPath();
$filePath =& $this->resizedFilepath;
$scale = 2;
// SCALE_INSIDE
$options = array('quality' => 85);
// TODO as param
} else {
return;
}
}
// define file paths
$newPhotoFilepath = $path . DS . $this->folder->getFolderPath() . DS . $this->filename;
$photoFilepath = $this->gallery->getPhotosPath() . DS . $this->folder->getFolderPath() . DS . $this->filename;
// check if thumbnail already exists and create it if not
if (!JFile::exists($newPhotoFilepath)) {
// TODO add check if file size (width and height) is correct
// resize image
$photo = new JImage($photoFilepath);
$newPhoto = $photo->resize($width, $height, true, $scale);
// crop image
if ($crop) {
$offsetLeft = ($newPhoto->getWidth() - $width) / 2;
$offsetTop = ($newPhoto->getHeight() - $height) / 2;
$newPhoto->crop($width, $height, $offsetLeft, $offsetTop, false);
}
// create folders (recursive) and write file
if (JFolder::create($path . DS . $this->folder->getFolderPath())) {
$newPhoto->toFile($newPhotoFilepath, IMAGETYPE_JPEG, $options);
}
}
$filePath = str_replace($this->gallery->getCachePath(), '', $newPhotoFilepath);
}
示例6: explode
$mime_types = $sconfig->mime_types;
$okMIMETypes = $mime_types;
$validFileTypes = explode(",", $okMIMETypes);
if (is_int($imageinfo[0]) || is_int($imageinfo[1]) || in_array($imageinfo['mime'], $validFileTypes)) {
$image['name'] = preg_replace("/[^A-Za-z.0-9]/i", "-", $image['name']);
$newName = 'profile-' . $uid . '-' . $time . '-' . $image['name'];
$newName2 = 'profile-x-' . $uid . '-' . $time . '-' . $image['name'];
$uploadPath = $base_path . $uid . DS . $newName;
$uploadPath2 = $base_path . $uid . DS . $newName2;
$stampPath = JPATH_COMPONENT . DS . 'assets' . DS . 'images' . DS . 'stamp.png';
$file_name = $newName2;
JFile::upload($image['tmp_name'], $uploadPath);
####################
$image = new JImage($uploadPath);
$properties = JImage::getImageFileProperties($uploadPath);
$resizedImage = $image->resize('250', '250', true);
$mime = $properties->mime;
if ($mime == 'image/jpeg') {
$type = IMAGETYPE_JPEG;
} elseif ($mime = 'image/png') {
$type = IMAGETYPE_PNG;
} elseif ($mime = 'image/gif') {
$type = IMAGETYPE_GIF;
}
$resizedImage->toFile($uploadPath, $type);
//create image .....
//echo 'creem imaginea<br />';
watermark_image($uploadPath, $uploadPath2, $mime);
####################
######adaugare in baza de date
$upd_poza = ", `poza` = '" . $file_name . "'";
示例7: onUserAfterSave
//.........这里部分代码省略.........
if (empty($file['name'])) {
return true;
}
$fileTypes = explode('.', $file['name']);
if (count($fileTypes) < 2) {
// There seems to be no extension.
throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TYPE'));
return false;
}
array_shift($fileTypes);
// Check if the file has an executable extension.
$executable = array('php', 'js', 'exe', 'phtml', 'java', 'perl', 'py', 'asp', 'dll', 'go', 'ade', 'adp', 'bat', 'chm', 'cmd', 'com', 'cpl', 'hta', 'ins', 'isp', 'jse', 'lib', 'mde', 'msc', 'msp', 'mst', 'pif', 'scr', 'sct', 'shb', 'sys', 'vb', 'vbe', 'vbs', 'vxd', 'wsc', 'wsf', 'wsh');
$check = array_intersect($fileTypes, $executable);
if (!empty($check)) {
throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TYPE'));
return false;
}
$fileType = array_pop($fileTypes);
$allowable = array_map('trim', explode(',', $this->params->get('allowed_extensions')));
if ($fileType == '' || $fileType == false || !in_array($fileType, $allowable)) {
throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TYPE'));
return false;
}
$uploadMaxSize = $this->params->get('max_size', 0) * 1024 * 1024;
$uploadMaxFileSize = $this->toBytes(ini_get('upload_max_filesize'));
if ($file['error'] == 1 || $uploadMaxSize > 0 && $file['size'] > $uploadMaxSize || $uploadMaxFileSize > 0 && $file['size'] > $uploadMaxFileSize) {
throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TOO_LARGE'));
return false;
}
// Make the file name unique.
$md5String = $userId . $file['name'] . JFactory::getDate();
$avatarFileName = JFile::makeSafe(md5($md5String));
if (empty($avatarFileName)) {
// No file name after the name was cleaned by JFile::makeSafe.
throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_NO_FILENAME'));
return false;
}
$avatarPath = JPath::clean($avatarFolder . '/' . $avatarFileName . '.' . $this->extension);
if (JFile::exists($avatarPath)) {
// A file with this name already exists. It is almost impossible.
throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_EXISTS'));
return false;
}
// Start resizing the file.
$avatar = new JImage($file['tmp_name']);
$originalWidth = $avatar->getWidth();
$originalHeight = $avatar->getHeight();
$ratio = $originalWidth / $originalHeight;
$maxWidth = (int) $this->params->get('width', 100);
$maxHeight = (int) $this->params->get('height', 100);
// Invalid value in the plugin configuration. Set avatar width to 100.
if ($maxWidth <= 0) {
$maxWidth = 100;
}
if ($maxHeight <= 0) {
$maxHeight = 100;
}
if ($originalWidth > $maxWidth) {
$ratio = $originalWidth / $originalHeight;
$newWidth = $maxWidth;
$newHeight = $newWidth / $ratio;
if ($newHeight > $maxHeight) {
$ratio = $newWidth / $newHeight;
$newHeight = $maxHeight;
$newWidth = $newHeight * $ratio;
}
} elseif ($originalHeight > $maxHeight) {
$ratio = $originalWidth / $originalHeight;
$newHeight = $maxHeight;
$newWidth = $newHeight * $ratio;
if ($newWidth > $maxWidth) {
$ratio = $newWidth / $newHeight;
$newWidth = $maxWidth;
$newHeight = $newWidth / $ratio;
}
} else {
$newWidth = $originalWidth;
$newHeight = $originalHeight;
}
$resizedAvatar = $avatar->resize($newWidth, $newHeight, true);
$resizedAvatar->toFile($avatarPath);
// Delete current avatar if exists.
$this->deleteAvatar($userId);
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// Save avatar's file name to database.
if (!empty($currentAvatar)) {
$query->update($db->qn('#__user_profiles'))->set($db->qn('profile_value') . ' = ' . $db->q($avatarFileName))->where($db->qn('user_id') . ' = ' . $db->q($userId))->where($db->qn('profile_key') . ' = ' . $db->quote($this->profileKey));
} else {
$query->insert($db->qn('#__user_profiles'))->columns($db->qn(array('user_id', 'profile_key', 'profile_value', 'ordering')))->values($db->q($userId) . ', ' . $db->q($this->profileKey) . ', ' . $db->q($avatarFileName) . ', ' . $db->q('1'));
}
$db->setQuery($query)->execute();
// Check for a database error.
if ($error = $db->getErrorMsg()) {
throw new RuntimeException($error);
return false;
}
}
return true;
}
示例8: uploadImage
/**
* Store the file in a folder of the extension.
*
* @param array $image
* @param bool $resizeImage
*
* @throws \RuntimeException
* @throws \Exception
* @throws \InvalidArgumentException
*
* @return array
*/
public function uploadImage($image, $resizeImage = false)
{
$app = JFactory::getApplication();
/** @var $app JApplicationSite */
$uploadedFile = ArrayHelper::getValue($image, 'tmp_name');
$uploadedName = ArrayHelper::getValue($image, 'name');
$errorCode = ArrayHelper::getValue($image, 'error');
$params = JComponentHelper::getParams($this->option);
/** @var $params Joomla\Registry\Registry */
$filesystemHelper = new Prism\Filesystem\Helper($params);
$mediaFolder = $filesystemHelper->getMediaFolder();
$destinationFolder = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $mediaFolder);
$temporaryFolder = $app->get('tmp_path');
// Joomla! media extension parameters
$mediaParams = JComponentHelper::getParams('com_media');
/** @var $mediaParams Joomla\Registry\Registry */
$file = new Prism\File\File();
// Prepare size validator.
$KB = 1024 * 1024;
$fileSize = (int) $app->input->server->get('CONTENT_LENGTH');
$uploadMaxSize = $mediaParams->get('upload_maxsize') * $KB;
// Prepare file validators.
$sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize);
$serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE));
$imageValidator = new Prism\File\Validator\Image($uploadedFile, $uploadedName);
// Get allowed mime types from media manager options
$mimeTypes = explode(',', $mediaParams->get('upload_mime'));
$imageValidator->setMimeTypes($mimeTypes);
// Get allowed image extensions from media manager options
$imageExtensions = explode(',', $mediaParams->get('image_extensions'));
$imageValidator->setImageExtensions($imageExtensions);
$file->addValidator($sizeValidator)->addValidator($serverValidator)->addValidator($imageValidator);
// Validate the file
if (!$file->isValid()) {
throw new RuntimeException($file->getError());
}
// Generate temporary file name
$ext = strtolower(JFile::makeSafe(JFile::getExt($image['name'])));
$generatedName = Prism\Utilities\StringHelper::generateRandomString();
$temporaryFile = $generatedName . '_reward.' . $ext;
$temporaryDestination = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $temporaryFile);
// Prepare uploader object.
$uploader = new Prism\File\Uploader\Local($uploadedFile);
$uploader->setDestination($temporaryDestination);
// Upload temporary file
$file->setUploader($uploader);
$file->upload();
$temporaryFile = $file->getFile();
if (!is_file($temporaryFile)) {
throw new Exception('COM_GAMIFICATION_ERROR_FILE_CANT_BE_UPLOADED');
}
// Resize image
$image = new JImage();
$image->loadFile($temporaryFile);
if (!$image->isLoaded()) {
throw new Exception(JText::sprintf('COM_GAMIFICATION_ERROR_FILE_NOT_FOUND', $temporaryDestination));
}
$imageName = $generatedName . '_image.png';
$smallName = $generatedName . '_small.png';
$squareName = $generatedName . '_square.png';
$imageFile = $destinationFolder . DIRECTORY_SEPARATOR . $imageName;
$smallFile = $destinationFolder . DIRECTORY_SEPARATOR . $smallName;
$squareFile = $destinationFolder . DIRECTORY_SEPARATOR . $squareName;
$scaleOption = $params->get('image_resizing_scale', JImage::SCALE_INSIDE);
// Create main image
if (!$resizeImage) {
$image->toFile($imageFile, IMAGETYPE_PNG);
} else {
$width = $params->get('image_width', 200);
$height = $params->get('image_height', 200);
$image->resize($width, $height, false, $scaleOption);
$image->toFile($imageFile, IMAGETYPE_PNG);
}
// Create small image
$width = $params->get('image_small_width', 100);
$height = $params->get('image_small_height', 100);
$image->resize($width, $height, false, $scaleOption);
$image->toFile($smallFile, IMAGETYPE_PNG);
// Create square image
$width = $params->get('image_square_width', 50);
$height = $params->get('image_square_height', 50);
$image->resize($width, $height, false, $scaleOption);
$image->toFile($squareFile, IMAGETYPE_PNG);
$names = array('image' => $imageName, 'image_small' => $smallName, 'image_square' => $squareName);
// Remove the temporary file.
if (JFile::exists($temporaryFile)) {
JFile::delete($temporaryFile);
}
//.........这里部分代码省略.........
示例9: uploadImage
/**
* Upload an image
*
* @param array $image Array with information about uploaded file.
*
* @throws RuntimeException
* @return array
*/
public function uploadImage($image)
{
$app = JFactory::getApplication();
/** @var $app JApplicationAdministrator */
$uploadedFile = Joomla\Utilities\ArrayHelper::getValue($image, 'tmp_name');
$uploadedName = Joomla\Utilities\ArrayHelper::getValue($image, 'name');
$errorCode = Joomla\Utilities\ArrayHelper::getValue($image, 'error');
$tmpFolder = $app->get("tmp_path");
/** @var $params Joomla\Registry\Registry */
$params = JComponentHelper::getParams($this->option);
$destFolder = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $params->get("images_directory", "/images/profiles"));
$options = array("width" => $params->get("image_width"), "height" => $params->get("image_height"), "small_width" => $params->get("image_small_width"), "small_height" => $params->get("image_small_height"), "square_width" => $params->get("image_square_width"), "square_height" => $params->get("image_square_height"), "icon_width" => $params->get("image_icon_width"), "icon_height" => $params->get("image_icon_height"));
// Joomla! media extension parameters
/** @var $mediaParams Joomla\Registry\Registry */
$mediaParams = JComponentHelper::getParams("com_media");
jimport("itprism.file");
jimport("itprism.file.uploader.local");
jimport("itprism.file.validator.size");
jimport("itprism.file.validator.image");
jimport("itprism.file.validator.server");
$file = new Prism\File\File();
// Prepare size validator.
$KB = 1024 * 1024;
$fileSize = (int) $app->input->server->get('CONTENT_LENGTH');
$uploadMaxSize = $mediaParams->get("upload_maxsize") * $KB;
// Prepare file size validator
$sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize);
// Prepare server validator.
$serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE));
// Prepare image validator.
$imageValidator = new Prism\File\Validator\Image($uploadedFile, $uploadedName);
// Get allowed mime types from media manager options
$mimeTypes = explode(",", $mediaParams->get("upload_mime"));
$imageValidator->setMimeTypes($mimeTypes);
// Get allowed image extensions from media manager options
$imageExtensions = explode(",", $mediaParams->get("image_extensions"));
$imageValidator->setImageExtensions($imageExtensions);
$file->addValidator($sizeValidator)->addValidator($imageValidator)->addValidator($serverValidator);
// Validate the file
if (!$file->isValid()) {
throw new RuntimeException($file->getError());
}
// Generate temporary file name
$ext = JFile::makeSafe(JFile::getExt($image['name']));
$generatedName = new Prism\String();
$generatedName->generateRandomString(32);
$tmpDestFile = $tmpFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext;
// Prepare uploader object.
$uploader = new Prism\File\Uploader\Local($uploadedFile);
$uploader->setDestination($tmpDestFile);
// Upload temporary file
$file->setUploader($uploader);
$file->upload();
// Get file
$tmpSourceFile = $file->getFile();
if (!is_file($tmpSourceFile)) {
throw new RuntimeException('COM_SOCIALCOMMUNITY_ERROR_FILE_CANT_BE_UPLOADED');
}
// Generate file names for the image files.
$generatedName->generateRandomString(32);
$imageName = $generatedName . "_image.png";
$smallName = $generatedName . "_small.png";
$squareName = $generatedName . "_square.png";
$iconName = $generatedName . "_icon.png";
// Resize image
$image = new JImage();
$image->loadFile($tmpSourceFile);
if (!$image->isLoaded()) {
throw new RuntimeException(JText::sprintf('COM_SOCIALCOMMUNITY_ERROR_FILE_NOT_FOUND', $tmpSourceFile));
}
$imageFile = $destFolder . DIRECTORY_SEPARATOR . $imageName;
$smallFile = $destFolder . DIRECTORY_SEPARATOR . $smallName;
$squareFile = $destFolder . DIRECTORY_SEPARATOR . $squareName;
$iconFile = $destFolder . DIRECTORY_SEPARATOR . $iconName;
// Create profile picture
$width = Joomla\Utilities\ArrayHelper::getValue($options, "image_width", 200);
$height = Joomla\Utilities\ArrayHelper::getValue($options, "image_height", 200);
$image->resize($width, $height, false);
$image->toFile($imageFile, IMAGETYPE_PNG);
// Create small profile picture
$width = Joomla\Utilities\ArrayHelper::getValue($options, "small_width", 100);
$height = Joomla\Utilities\ArrayHelper::getValue($options, "small_height", 100);
$image->resize($width, $height, false);
$image->toFile($smallFile, IMAGETYPE_PNG);
// Create square picture
$width = Joomla\Utilities\ArrayHelper::getValue($options, "square_width", 50);
$height = Joomla\Utilities\ArrayHelper::getValue($options, "square_height", 50);
$image->resize($width, $height, false);
$image->toFile($squareFile, IMAGETYPE_PNG);
// Create icon picture
$width = Joomla\Utilities\ArrayHelper::getValue($options, "icon_width", 24);
$height = Joomla\Utilities\ArrayHelper::getValue($options, "icon_height", 24);
//.........这里部分代码省略.........
示例10: cropImage
/**
* Crop the image and generates smaller ones.
*
* @param string $file
* @param array $options
* @param Joomla\Registry\Registry $params
*
* @throws Exception
*
* @return array
*/
public function cropImage($file, $options, $params)
{
// Resize image
$image = new JImage();
$image->loadFile($file);
if (!$image->isLoaded()) {
throw new Exception(JText::sprintf('COM_SOCIALCOMMUNITY_ERROR_FILE_NOT_FOUND', $file));
}
$destinationFolder = Joomla\Utilities\ArrayHelper::getValue($options, 'destination');
// Generate temporary file name
$generatedName = Prism\Utilities\StringHelper::generateRandomString(24);
$profileName = $generatedName . '_profile.png';
$smallName = $generatedName . '_small.png';
$squareName = $generatedName . '_square.png';
$iconName = $generatedName . '_icon.png';
$imageFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $profileName);
$smallFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $smallName);
$squareFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $squareName);
$iconFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $iconName);
// Create profile image.
$width = Joomla\Utilities\ArrayHelper::getValue($options, 'width', 200);
$width = $width < 25 ? 50 : $width;
$height = Joomla\Utilities\ArrayHelper::getValue($options, 'height', 200);
$height = $height < 25 ? 50 : $height;
$left = Joomla\Utilities\ArrayHelper::getValue($options, 'x', 0);
$top = Joomla\Utilities\ArrayHelper::getValue($options, 'y', 0);
$image->crop($width, $height, $left, $top, false);
// Resize to general size.
$width = $params->get('image_width', 200);
$width = $width < 25 ? 50 : $width;
$height = $params->get('image_height', 200);
$height = $height < 25 ? 50 : $height;
$image->resize($width, $height, false);
// Store to file.
$image->toFile($imageFile, IMAGETYPE_PNG);
// Create small image.
$width = $params->get('image_small_width', 100);
$height = $params->get('image_small_height', 100);
$image->resize($width, $height, false);
$image->toFile($smallFile, IMAGETYPE_PNG);
// Create square image.
$width = $params->get('image_square_width', 50);
$height = $params->get('image_square_height', 50);
$image->resize($width, $height, false);
$image->toFile($squareFile, IMAGETYPE_PNG);
// Create icon image.
$width = $params->get('image_icon_width', 25);
$height = $params->get('image_icon_height', 25);
$image->resize($width, $height, false);
$image->toFile($iconFile, IMAGETYPE_PNG);
$names = array('image_profile' => $profileName, 'image_small' => $smallName, 'image_square' => $squareName, 'image_icon' => $iconName);
// Remove the temporary file.
if (JFile::exists($file)) {
JFile::delete($file);
}
return $names;
}
示例11: resize
/**
* Resize the temporary file to new one.
*
* <code>
* $image = $this->input->files->get('media', array(), 'array');
* $rootFolder = "/root/joomla/tmp";
*
* $resizeOptions = array(
* 'width' => $options['thumb_width'],
* 'height' => $options['thumb_height'],
* 'scale' => $options['thumb_scale']
* );
*
* $file = new Prism\File\Image($image, $rootFolder);
*
* $file->upload();
* $fileData = $file->resize($resize);
* </code>
*
* @param array $options
* @param bool $replace Replace the original file with the new one.
* @param string $prefix Filename prefix.
*
* @throws \RuntimeException
*
* @return array
*/
public function resize(array $options, $replace = false, $prefix = '')
{
if (!$this->file) {
throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND_S', $this->file));
}
// Resize image.
$image = new \JImage();
$image->loadFile($this->file);
if (!$image->isLoaded()) {
throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND_S', $this->file));
}
// Resize to general size.
$width = ArrayHelper::getValue($options, 'width', 640);
$width = $width < 50 ? 50 : $width;
$height = ArrayHelper::getValue($options, 'height', 480);
$height = $height < 50 ? 50 : $height;
$scale = ArrayHelper::getValue($options, 'scale', \JImage::SCALE_INSIDE);
$image->resize($width, $height, false, $scale);
// Generate new name.
$generatedName = StringHelper::generateRandomString($this->options->get('filename_length', 16)) . '.png';
if (is_string($prefix) and $prefix !== '') {
$generatedName = $prefix . $generatedName;
}
$file = \JPath::clean($this->rootFolder . '/' . $generatedName);
// Store to file.
$image->toFile($file, IMAGETYPE_PNG);
if ($replace) {
\JFile::delete($this->file);
$this->file = $file;
}
// Prepare meta data about the file.
$fileData = array('filename' => $generatedName, 'filepath' => $file, 'type' => 'image');
$fileData = array_merge($fileData, $this->prepareImageProperties($this->file));
return $fileData;
}
示例12: profileImage
public static function profileImage($profileID, $variable = 'profile')
{
$files = JRequest::getVar('jform', null, 'files');
$jform = JRequest::getVar('jform', null, 'ARRAY');
// Check that user want upload image or delete image
$image_delete = empty($jform[$variable]['image_delete']) ? false : true;
$image_error = empty($variable) ? $files['error']['image'] : $files['error'][$variable]['image'];
$image_tmp_name = empty($variable) ? $files['tmp_name']['image'] : $files['tmp_name'][$variable]['image'];
// Minimum image size
$imageSize = 200;
$profileImage = -1;
// Upload Profile Image
if ($image_error == 0 && !$image_delete) {
// Resize Image
$image = new JImage($image_tmp_name);
$sourceWidth = $image->getWidth();
$sourceHeight = $image->getHeight();
if ($sourceWidth < $imageSize || $sourceHeight < $imageSize) {
return JText::sprintf('COM_SIBDIET_ERROR_PROFILE_IMAGE_TOO_SMALL', $imageSize);
}
// Set image name to user profile ID
$image_filename = $profileID . '.jpg';
$ratio = max($sourceWidth, $sourceHeight) / $imageSize;
$ratio = max($ratio, 1.0);
$resizedWidth = (int) ($sourceWidth / $ratio);
$resizedHeight = (int) ($sourceHeight / $ratio);
$resized = $image->resize($resizedWidth, $resizedHeight, true, JImage::SCALE_INSIDE);
$resized->toFile(JPATH_ROOT . '/images/sibdiet/profiles/' . $image_filename, 'IMAGETYPE_JPEG');
} elseif ($image_delete) {
$image_path = JPATH_ROOT . '/images/sibdiet/profiles/' . $profileID . '.jpg';
jimport('joomla.filesystem.file');
if (JFile::exists($image_path)) {
JFile::delete($image_path);
}
}
return true;
}
示例13: crop
public static function crop($srcPath, $destPath, $cropWidth, $cropHeight, $sourceX, $sourceY, $cropMaxWidth = 64, $cropMaxHeight = 64)
{
$jImage = new JImage($srcPath);
$imageInfo = JImage::getImageFileProperties($srcPath);
try {
if ($cropWidth == 0 && $cropHeight == 0) {
$cropThumb = $jImage->resize($cropMaxWidth, $cropMaxHeight);
} else {
$cropThumb = $jImage->crop($cropWidth, $cropHeight, $sourceX, $sourceY, true);
if ($cropMaxWidth <= $cropWidth || $cropMaxHeight <= $cropHeight) {
$cropThumb = $cropThumb->resize($cropMaxWidth, $cropMaxHeight);
}
}
$option = $imageInfo->type == IMAGETYPE_PNG ? self::$pngOption : self::$otherOption;
$cropThumb->toFile($destPath, $imageInfo->type, $option);
} catch (Exception $ex) {
return false;
}
return true;
}
示例14: resize
public static function resize($filename, $width, $height)
{
$path = JPath::clean($filename);
$JImage = new JImage($path);
$info = pathinfo($filename);
$extension = $info['extension'];
$old_image = basename($filename);
$new_image = $info['filename'] . '-' . $width . 'x' . $height . '.' . $extension;
$ret = '';
if (!file_exists(DIR_IMAGE . '/thumbs' . $new_image) || filemtime(DIR_IMAGE . '/' . $old_image) > filemtime(DIR_IMAGE . '/thumbs' . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', DIR_IMAGE . '/thumbs' . $new_image)));
foreach ($directories as $directory) {
if (!empty($directory)) {
$path = $path . '/' . $directory;
if (!file_exists($path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
}
$image = $JImage->resize($width, $height, true, 1);
if ($image->toFile(DIR_IMAGE . '/thumbs' . $new_image)) {
$ret = JUri::root() . 'media/openhrm/images/thumbs' . $new_image;
}
} else {
$ret = JUri::root() . 'media/openhrm/images/thumbs' . $new_image;
}
return $ret;
}
示例15: validateInput
public function validateInput()
{
jimport('joomla.filesystem.file');
jimport('joomla.image.image');
$app = JFactory::getApplication();
$fm = JRequest::getVar('jform', NULL, 'post');
if (!empty($fm)) {
$site_name = $fm['site_name'];
$site_metadesc = $fm['site_metadesc'];
$site_metakeys = $fm['site_metakeys'];
$site_offline = $fm['site_offline'];
$admin_email = $fm['admin_email'];
$admin_user = $fm['admin_user'];
$admin_password = $fm['admin_password'];
$admin_password2 = $fm['admin_password2'];
} else {
$site_name = NULL;
$site_metadesc = NULL;
$site_metakeys = NULL;
$site_offline = NULL;
$admin_email = NULL;
$admin_user = NULL;
$admin_password = NULL;
$admin_password2 = NULL;
}
$files = JRequest::getVar('jform', NULL, 'files');
$msg = "Usted debe corregir y completar los siguientes datos antes de continuar:<br />";
$disc = true;
if (empty($site_name)) {
$msg .= "- Debe ingresar un nombre para el sitio.<br />";
$disc &= false;
}
if (empty($admin_email)) {
$msg .= "- Debe ingresar el correo del administrador.<br />";
$disc &= false;
}
if (empty($admin_user)) {
$msg .= "- Debe ingresar un nombre de usuario.<br />";
$disc &= false;
}
if (empty($admin_password)) {
$msg .= "- Debe ingresar una contraseña.<br />";
$disc &= false;
}
if (empty($admin_password2)) {
$msg .= "- Debe confirmar la contraseña.<br />";
$disc &= false;
}
if ($admin_password != $admin_password2) {
$msg .= "- Las contraseñas no coinciden.<br />";
$disc &= false;
}
if ($disc) {
if (!empty($files['tmp_name']['site_logo'])) {
// Set the path to the file
$file = $files['tmp_name']['site_logo'];
// Instantiate our JImage object
$image = new JImage($file);
// Get the file's properties
$properties = $image->getImageFileProperties($file);
// Resize the file as a new object
$logo1 = $image->resize('200px', '74px', true);
$logo3 = $image->resize('250px', '30px', true);
// Determine the MIME of the original file to get the proper type for output
$mime = $properties->mime;
if ($mime == 'image/jpeg') {
$type = IMAGETYPE_JPEG;
} elseif ($mime == 'image/png') {
$type = IMAGETYPE_PNG;
} elseif ($mime == 'image/gif') {
$type = IMAGETYPE_GIF;
}
// Store the resized image to a new file
$logo1->toFile(JPATH_ROOT . DS . 'images' . DS . 'logos' . DS . 'jokte-logo-front.png', $type);
$logo3->toFile(JPATH_ROOT . DS . 'administrator' . DS . 'templates' . DS . 'storkantu' . DS . 'images' . DS . 'logo.png', $type);
}
$site_name = $fm['site_name'];
$site_metadesc = $fm['site_metadesc'];
$site_metakeys = $fm['site_metakeys'];
$site_offline = $fm['site_offline'];
$admin_email = $fm['admin_email'];
$admin_user = $fm['admin_user'];
$admin_password = $fm['admin_password'];
$admin_password2 = $fm['admin_password2'];
$fmData = '&jform[site_name]=' . $site_name;
$fmData .= '&jform[site_metadesc]=' . $site_metadesc;
$fmData .= '&jform[site_metakeys]=' . $site_metakeys;
$fmData .= '&jform[site_offline]=' . $site_offline;
$fmData .= '&jform[admin_email]=' . $admin_email;
$fmData .= '&jform[admin_user]=' . $admin_user;
$fmData .= '&jform[admin_password]=' . $admin_password;
$fmData .= '&jform[admin_password2]=' . $admin_password2;
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$app->redirect('?view=remove&task=setup.saveconfig' . $fmData . "&{$tkn}=1");
} elseif (!empty($fm)) {
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$app->redirect('?view=site', $msg, 'warning');
}
}