本文整理汇总了PHP中SimpleImage::resizeToFill方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleImage::resizeToFill方法的具体用法?PHP SimpleImage::resizeToFill怎么用?PHP SimpleImage::resizeToFill使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleImage
的用法示例。
在下文中一共展示了SimpleImage::resizeToFill方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bindAttachments
public function bindAttachments()
{
$mainframe = JFactory::getApplication();
$config = DiscussHelper::getConfig();
// @task: Do not allow file attachments if its disabled.
if (!$config->get('attachment_questions')) {
return false;
}
$allowed = explode(',', $config->get('main_attachment_extension'));
$files = JRequest::getVar('filedata', array(), 'FILES');
if (empty($files)) {
return false;
}
$total = count($files['name']);
// @rule: Handle empty files.
if (empty($files['name'][0])) {
$total = 0;
}
if ($total < 1) {
return false;
}
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
jimport('joomla.utilities.utility');
// @rule: Create default media path
$path = DISCUSS_MEDIA . '/' . trim($config->get('attachment_path'), DIRECTORY_SEPARATOR);
if (!JFolder::exists($path)) {
JFolder::create($path);
JFile::copy(DISCUSS_ROOT . '/index.html', $path . '/index.html');
}
$maxSize = (double) $config->get('attachment_maxsize') * 1024 * 1024;
for ($i = 0; $i < $total; $i++) {
$extension = JFile::getExt($files['name'][$i]);
// Skip empty data's.
if (!$extension) {
continue;
}
// @rule: Check for allowed extensions
if (!isset($extension) || !in_array(strtolower($extension), $allowed)) {
$mainframe->enqueueMessage(JText::sprintf('COM_EASYDISCUSS_FILE_ATTACHMENTS_INVALID_EXTENSION', $files['name'][$i]), 'error');
$this->setError(JText::sprintf('COM_EASYDISCUSS_FILE_ATTACHMENTS_INVALID_EXTENSION', $files['name'][$i]));
return false;
} else {
$size = $files['size'][$i];
// @rule: File size should not exceed maximum allowed size
if (!empty($size) && ($size < $maxSize || $maxSize == 0)) {
$name = DiscussHelper::getHash($files['name'][$i] . DiscussHelper::getDate()->toMySQL());
$attachment = DiscussHelper::getTable('Attachments');
$attachment->set('path', $name);
$attachment->set('title', $files['name'][$i]);
$attachment->set('uid', $this->id);
$attachment->set('type', $this->getType());
$attachment->set('created', DiscussHelper::getDate()->toMySQL());
$attachment->set('published', true);
$attachment->set('mime', $files['type'][$i]);
$attachment->set('size', $size);
JFile::copy($files['tmp_name'][$i], $path . '/' . $name);
$attachment->store();
// Create a thumbnail if attachment is an image
if (DiscussHelper::getHelper('Image')->isImage($files['name'][$i])) {
require_once DISCUSS_CLASSES . '/simpleimage.php';
$image = new SimpleImage();
$image->load($files['tmp_name'][$i]);
$image->resizeToFill(160, 120);
$image->save($path . '/' . $name . '_thumb', $image->image_type);
}
} else {
$mainframe->enqueueMessage(JText::sprintf('COM_EASYDISCUSS_FILE_ATTACHMENTS_MAX_SIZE_EXCLUDED', $files['name'][$i], $config->get('attachment_maxsize')), 'error');
$this->setError(JText::sprintf('COM_EASYDISCUSS_FILE_ATTACHMENTS_MAX_SIZE_EXCLUDED', $files['name'][$i], $config->get('attachment_maxsize')));
return false;
}
}
}
return true;
}
示例2: mapKunenaItem
private function mapKunenaItem($kItem, &$item, $parent = null)
{
$content = $this->getKunenaMessage($kItem);
$hits = isset($kItem->threadhits) ? $kItem->threadhits : $kItem->hits;
$lastreplied = isset($kItem->threadlastreplied) ? $kItem->threadlastreplied : $kItem->time;
$item->set('content', $content);
$subject = $kItem->subject;
if (!$parent && $kItem->threadsubject) {
$subject = $kItem->threadsubject;
}
$item->set('title', $subject);
$item->set('category_id', $this->getNewCategory($kItem));
$item->set('user_id', $kItem->userid);
$item->set('user_type', DISCUSS_POSTER_MEMBER);
$item->set('hits', $hits);
$item->set('created', DiscussHelper::getDate($kItem->time)->toMySQL());
$item->set('modified', DiscussHelper::getDate($kItem->time)->toMySQL());
$item->set('replied', DiscussHelper::getDate($lastreplied)->toMySQL());
$item->set('poster_name', $kItem->name);
$item->set('ip', $kItem->ip);
$item->set('content_type', 'bbcode');
$item->set('parent_id', 0);
// @task: If this is a child post, we definitely have the item's id.
if ($parent) {
$item->set('parent_id', $parent->id);
}
$item->set('islock', $kItem->locked);
$item->set('poster_email', $kItem->email);
$state = $kItem->hold == 0 ? DISCUSS_ID_PUBLISHED : DISCUSS_ID_UNPUBLISHED;
$item->set('published', $state);
if (!$kItem->userid) {
$item->set('user_type', DISCUSS_POSTER_GUEST);
}
$item->store();
// @task: Get attachments
$files = $this->getKunenaAttachments($kItem);
if ($files) {
foreach ($files as $kAttachment) {
$attachment = DiscussHelper::getTable('Attachments');
$attachment->set('uid', $item->id);
$attachment->set('size', $kAttachment->size);
$attachment->set('title', $kAttachment->filename);
$attachment->set('type', $item->getType());
$attachment->set('published', DISCUSS_ID_PUBLISHED);
$attachment->set('mime', $kAttachment->filetype);
// Regenerate the path
$isJoomla30 = DiscussHelper::isJoomla30();
if ($isJoomla30) {
// JUtility::getHash is deprecated
$path = JApplication::getHash($kAttachment->filename . DiscussHelper::getDate()->toMySQL());
} else {
$path = JUtility::getHash($kAttachment->filename . DiscussHelper::getDate()->toMySQL());
}
$attachment->set('path', $path);
// Copy files over.
$config = DiscussHelper::getConfig();
$folderPath = DISCUSS_MEDIA . '/' . trim($config->get('attachment_path'), DIRECTORY_SEPARATOR);
$storage = $folderPath . '/' . $path;
$kStorage = JPATH_ROOT . '/' . rtrim($kAttachment->folder, '/') . '/' . $kAttachment->filename;
// create folder if it not exists
if (!JFolder::exists($folderPath)) {
JFolder::create($folderPath);
JFile::copy(DISCUSS_ROOT . '/index.html', $path . '/index.html');
}
if (JFile::exists($kStorage)) {
JFile::copy($kStorage, $storage);
if (DiscussHelper::getHelper('Image')->isImage($kAttachment->filename)) {
require_once DISCUSS_CLASSES . '/simpleimage.php';
$image = new SimpleImage();
@$image->load($kStorage);
@$image->resizeToFill(160, 120);
@$image->save($storage . '_thumb', $image->image_type);
}
}
// @task: Since Kunena does not store this, we need to generate the own creation timestamp.
$attachment->set('created', DiscussHelper::getDate()->toMySQL());
$attachment->store();
}
}
//perform cleanup
$this->added('com_kunena', $item->id, $kItem->id, 'post');
}
示例3: uploadAvatar
//.........这里部分代码省略.........
$file['name'] = $my->id . '_' . JFile::makeSafe(md5($file['name'] . $date->toMySQL())) . '.' . strtolower($file_ext);
if (isset($file['name'])) {
$target_file_path = $upload_path;
$relative_target_file = $rel_upload_path . '/' . $file['name'];
$target_file = JPath::clean($target_file_path . '/' . JFile::makeSafe($file['name']));
$original = JPath::clean($target_file_path . '/' . 'original_' . JFile::makeSafe($file['name']));
$isNew = false;
require_once DISCUSS_HELPERS . '/image.php';
require_once DISCUSS_CLASSES . '/simpleimage.php';
if (!DiscussImageHelper::canUpload($file, $err)) {
if (!$isFromBackend) {
DiscussHelper::setMessageQueue(JText::_($err), 'error');
$mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&layout=edit', false));
} else {
// From backend
$mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), JText::_($err), 'error');
}
return;
}
if (0 != (int) $file['error']) {
if (!$isFromBackend) {
DiscussHelper::setMessageQueue($file['error'], 'error');
$mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&layout=edit', false));
} else {
//from backend
$mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), $file['error'], 'error');
}
return;
}
//rename the file 1st.
$oldAvatar = $profile->avatar;
$tempAvatar = '';
if ($oldAvatar != 'default.png') {
$session = JFactory::getSession();
$sessionId = $session->getToken();
$fileExt = JFile::getExt(JPath::clean($target_file_path . '/' . $oldAvatar));
$tempAvatar = JPath::clean($target_file_path . '/' . $sessionId . '.' . $fileExt);
// Test if old original file exists.
if (JFile::exists($target_file_path . '/original_' . $oldAvatar)) {
JFile::delete($target_file_path . '/original_' . $oldAvatar);
}
JFile::move($target_file_path . '/' . $oldAvatar, $tempAvatar);
} else {
$isNew = true;
}
if (JFile::exists($target_file)) {
if ($oldAvatar != 'default.png') {
//rename back to the previous one.
JFile::move($tempAvatar, $target_file_path . '/' . $oldAvatar);
}
if (!$isFromBackend) {
DiscussHelper::setMessageQueue(JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error');
$mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile', false));
} else {
//from backend
$mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error');
}
return;
}
if (JFolder::exists($target_file)) {
if ($oldAvatar != 'default.png') {
//rename back to the previous one.
JFile::move($tempAvatar, $target_file_path . '/' . $oldAvatar);
}
if (!$isFromBackend) {
DiscussHelper::setMessageQueue(JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error');
$mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile', false));
} else {
//from backend
$mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error');
}
return;
}
$configImageWidth = $config->get('layout_avatarwidth', 160);
$configImageHeight = $config->get('layout_avatarheight', 160);
$originalImageWidth = $config->get('layout_originalavatarwidth', 400);
$originalImageHeight = $config->get('layout_originalavatarheight', 400);
// Copy the original image files over
$image = new SimpleImage();
$image->load($file['tmp_name']);
//$image->resizeToFill( $originalImageWidth , $originalImageHeight );
// By Kevin Lankhorst
$image->resizeOriginal($originalImageWidth, $originalImageHeight, $configImageWidth, $configImageHeight);
$image->save($original, $image->image_type);
unset($image);
$image = new SimpleImage();
$image->load($file['tmp_name']);
$image->resizeToFill($configImageWidth, $configImageHeight);
$image->save($target_file, $image->image_type);
//now we update the user avatar. If needed, we remove the old avatar.
if ($oldAvatar != 'default.png') {
if (JFile::exists($tempAvatar)) {
JFile::delete($tempAvatar);
}
}
return JFile::makeSafe($file['name']);
} else {
return 'default.png';
}
}
示例4: processEmails
//.........这里部分代码省略.........
$path = DISCUSS_MEDIA . '/' . trim($config->get('attachment_path'), DIRECTORY_SEPARATOR);
if (!JFolder::exists($path)) {
JFolder::create($path);
JFile::copy(DISCUSS_ROOT . '/index.html', $path . '/index.html');
}
$maxSize = (double) $config->get('attachment_maxsize') * 1024 * 1024;
$extension = JFile::getExt($attachment['name']);
// Skip empty data's.
if (!$extension) {
continue;
}
$allowed = explode(',', $config->get('main_attachment_extension'));
// @rule: Check for allowed extensions
if (!isset($extension) || !in_array(strtolower($extension), $allowed)) {
echo 'Invalid extension.';
} else {
$size = $attachment['size'];
$name = $attachment['name'];
$mime = $attachment['mime'];
$tmpName = $attachment['tmp_name'];
// Check the mime contains the attachment type, if not we insert our own
$imgExts = array('jpg', 'png', 'gif', 'JPG', 'PNG', 'GIF', 'jpeg', 'JPEG');
if (in_array($mime, $imgExts)) {
$mime = 'image/' . $mime;
} else {
$mime = 'application/' . $mime;
}
// @rule: File size should not exceed maximum allowed size
if (!empty($size) && $size < $maxSize) {
$hash = DiscussHelper::getHash($name . DiscussHelper::getDate()->toMySQL());
$attachment = DiscussHelper::getTable('Attachments');
$attachment->set('path', $hash);
$attachment->set('title', $name);
$attachment->set('uid', $post->id);
$attachment->set('type', $isReply ? 'replies' : 'questions');
$attachment->set('created', DiscussHelper::getDate()->toMySQL());
$attachment->set('published', true);
$attachment->set('mime', $mime);
$attachment->set('size', $size);
if (!JFile::copy($tmpName, $path . '/' . $hash)) {
echo 'Copy failed from tmp to attachment folder';
}
$attachment->store();
// Create a thumbnail if attachment is an image
if (DiscussHelper::getHelper('Image')->isImage($name)) {
require_once DISCUSS_CLASSES . '/simpleimage.php';
$image = new SimpleImage();
$image->load($tmpName);
$image->resizeToFill(160, 120);
$image->save($path . '/' . $hash . '_thumb', $image->image_type);
}
// @task: Once the attachment is processed, delete the temporary file.
JFile::delete($tmpName);
} else {
echo 'Invalid extension ' . $name;
}
}
}
}
// Send notification email to the subscribers in the thread.
if ($isReply && $post->get('published') == DISCUSS_ID_PUBLISHED) {
self::replyNotifyUsers($post, $user, $senderName);
}
// @task: Increment the count.
$total += 1;
// @rule: Only send autoresponders when it's a new post.
if (!$isReply && $config->get('main_email_parser_receipt') && $post->get('published') == DISCUSS_ID_PUBLISHED) {
$sendAsHTML = (bool) $config->get('notify_html_format');
$theme = new DiscussThemes();
$postId = $post->get('id');
if ($isReply) {
$postId = $parentId;
}
$url = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $postId, false, true);
$emailData = array();
$emailData['postLink'] = $url;
if ($post->get('user_type') == DISCUSS_POSTER_GUEST) {
$emailData['postAuthor'] = $senderName;
} else {
$profile = DiscussHelper::getTable('Profile');
$profile->load($user->id);
$emailData['postAuthor'] = $profile->getName();
}
require_once DISCUSS_CLASSES . '/notification.php';
$notification = new DNotification();
$output = $notification->getEmailTemplateContent('email.accepted.responder.php', $emailData);
$app = JFactory::getApplication();
if (!$sendAsHTML) {
$output = strip_tags($output);
}
// @rule: Send confirmation message.
JUtility::sendMail($app->getCfg('mailfrom'), $app->getCfg('fromname'), $replyToEmail, '[#' . $post->id . ']: ' . $subject, $output, $sendAsHTML);
}
if (!$isReply && $post->get('published') == DISCUSS_ID_PUBLISHED) {
// Send email to subscribers about new post has created
Discusshelper::sendNotification($post, $post->parent_id, true, $post->user_id, DISCUSS_ID_PENDING);
}
echo JText::sprintf('COM_EASYDISCUSS_EMAIL_PARSED', $total);
}
}