本文整理汇总了PHP中Image::send_image方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::send_image方法的具体用法?PHP Image::send_image怎么用?PHP Image::send_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::send_image方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initErrImg
/**
* Gibt ein Fehlerbild aus
*
* @param int $width
* @param int $height
* @param string $text
* @param string $col_bg Hintergrundfarbe
* @param string $col_text Textfarbe
*/
private function _initErrImg($width = 100, $height = 80, $text = '', $col_bg = "000000255", $col_text = "200150080")
{
$text = $text == '' ? $this->_img_textes['img_not_found'] : $text;
$this->_img = new Image('');
$this->_img->create_image($width, $height, $text, $col_bg, $col_text);
$this->_img->send_image();
}
示例2: saveFieldValues
/**
* Save the extra fields values
* In order to save this function needs a item_id (user id, course id, etc)
* This function is used with $extraField->addElements()
* @param array $params array for the insertion into the *_field_values table
*
* @return mixed false on empty params, void otherwise
* @assert (array()) === false
*/
public function saveFieldValues($params)
{
foreach ($params as $key => $value) {
$found = strpos($key, '__persist__');
if ($found) {
$tempKey = str_replace('__persist__', '', $key);
if (!isset($params[$tempKey])) {
$params[$tempKey] = array();
}
}
}
if (empty($params['item_id'])) {
return false;
}
$type = $this->getExtraField()->getExtraFieldType();
// Parse params.
foreach ($params as $key => $value) {
if (substr($key, 0, 6) == 'extra_' || substr($key, 0, 7) == '_extra_') {
// An extra field.
$field_variable = substr($key, 6);
$extraFieldInfo = $this->getExtraField()->get_handler_field_info_by_field_variable($field_variable);
if ($extraFieldInfo) {
$commentVariable = 'extra_' . $field_variable . '_comment';
$comment = isset($params[$commentVariable]) ? $params[$commentVariable] : null;
switch ($extraFieldInfo['field_type']) {
case ExtraField::FIELD_TYPE_TAG:
if ($type == EntityExtraField::USER_FIELD_TYPE) {
UserManager::delete_user_tags($params['item_id'], $extraFieldInfo['id']);
UserManager::process_tags($value, $params['item_id'], $extraFieldInfo['id']);
} else {
$em = Database::getManager();
$tagValues = is_array($value) ? $value : [$value];
$tags = [];
foreach ($tagValues as $tagValue) {
$tagsResult = $em->getRepository('ChamiloCoreBundle:Tag')->findBy(['tag' => $tagValue, 'fieldId' => $extraFieldInfo['id']]);
if (empty($tagsResult)) {
$tag = new \Chamilo\CoreBundle\Entity\Tag();
$tag->setCount(0);
$tag->setFieldId($extraFieldInfo['id']);
$tag->setTag($tagValue);
$tags[] = $tag;
} else {
$tags = array_merge($tags, $tagsResult);
}
}
foreach ($tags as $tag) {
$fieldTags = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')->findBy(['fieldId' => $extraFieldInfo['id'], 'itemId' => $params['item_id'], 'tagId' => $tag->getId()]);
foreach ($fieldTags as $fieldTag) {
$em->remove($fieldTag);
$tag->setCount($tag->getCount() - 1);
$em->persist($tag);
$em->flush();
}
$tag->setCount($tag->getCount() + 1);
$em->persist($tag);
$em->flush();
$fieldRelTag = new Chamilo\CoreBundle\Entity\ExtraFieldRelTag();
$fieldRelTag->setFieldId($extraFieldInfo['id']);
$fieldRelTag->setItemId($params['item_id']);
$fieldRelTag->setTagId($tag->getId());
$em->persist($fieldRelTag);
$em->flush();
}
}
break;
case ExtraField::FIELD_TYPE_FILE_IMAGE:
$dirPermissions = api_get_permissions_for_new_directories();
switch ($this->type) {
case 'course':
$fileDir = api_get_path(SYS_UPLOAD_PATH) . "courses/";
$fileDirStored = "courses/";
break;
case 'session':
$fileDir = api_get_path(SYS_UPLOAD_PATH) . "sessions/";
$fileDirStored = "sessions/";
break;
case 'user':
$fileDir = UserManager::getUserPathById($params['item_id'], 'system');
$fileDirStored = UserManager::getUserPathById($params['item_id'], 'last');
break;
}
$fileName = ExtraField::FIELD_TYPE_FILE_IMAGE . "_{$params['item_id']}.png";
if (!file_exists($fileDir)) {
mkdir($fileDir, $dirPermissions, true);
}
if ($value['error'] == 0) {
$imageExtraField = new Image($value['tmp_name']);
$imageExtraField->send_image($fileDir . $fileName, -1, 'png');
$newParams = array('item_id' => $params['item_id'], 'field_id' => $extraFieldInfo['id'], 'value' => $fileDirStored . $fileName, 'comment' => $comment);
self::save($newParams);
}
//.........这里部分代码省略.........
示例3: update_user_picture
/**
* Creates new user photos in various sizes of a user, or deletes user photos.
* Note: This method relies on configuration setting from main/inc/conf/profile.conf.php
* @param int $user_id The user internal identification number.
* @param string $file The common file name for the newly created photos.
* It will be checked and modified for compatibility with the file system.
* If full name is provided, path component is ignored.
* If an empty name is provided, then old user photos are deleted only,
* @see UserManager::delete_user_picture() as the prefered way for deletion.
* @param string $source_file The full system name of the image from which user photos will be created.
* @return string/bool Returns the resulting common file name of created images which usually should be stored in database.
* When deletion is requested returns empty string. In case of internal error or negative validation returns FALSE.
*/
public static function update_user_picture($user_id, $file = null, $source_file = null)
{
if (empty($user_id)) {
return false;
}
$delete = empty($file);
if (empty($source_file)) {
$source_file = $file;
}
// User-reserved directory where photos have to be placed.
$path_info = self::get_user_picture_path_by_id($user_id, 'system');
$path = $path_info['dir'];
// If this directory does not exist - we create it.
if (!file_exists($path)) {
mkdir($path, api_get_permissions_for_new_directories(), true);
}
// The old photos (if any).
$old_file = $path_info['file'];
// Let us delete them.
if (!empty($old_file)) {
if (KEEP_THE_OLD_IMAGE_AFTER_CHANGE) {
$prefix = 'saved_' . date('Y_m_d_H_i_s') . '_' . uniqid('') . '_';
@rename($path . 'small_' . $old_file, $path . $prefix . 'small_' . $old_file);
@rename($path . 'medium_' . $old_file, $path . $prefix . 'medium_' . $old_file);
@rename($path . 'big_' . $old_file, $path . $prefix . 'big_' . $old_file);
@rename($path . $old_file, $path . $prefix . $old_file);
} else {
@unlink($path . 'small_' . $old_file);
@unlink($path . 'medium_' . $old_file);
@unlink($path . 'big_' . $old_file);
@unlink($path . $old_file);
}
}
// Exit if only deletion has been requested. Return an empty picture name.
if ($delete) {
return '';
}
// Validation 2.
$allowed_types = api_get_supported_image_extensions();
$file = str_replace('\\', '/', $file);
$filename = ($pos = strrpos($file, '/')) !== false ? substr($file, $pos + 1) : $file;
$extension = strtolower(substr(strrchr($filename, '.'), 1));
if (!in_array($extension, $allowed_types)) {
return false;
}
// This is the common name for the new photos.
if (KEEP_THE_NAME_WHEN_CHANGE_IMAGE && !empty($old_file)) {
$old_extension = strtolower(substr(strrchr($old_file, '.'), 1));
$filename = in_array($old_extension, $allowed_types) ? substr($old_file, 0, -strlen($old_extension)) : $old_file;
$filename = substr($filename, -1) == '.' ? $filename . $extension : $filename . '.' . $extension;
} else {
$filename = api_replace_dangerous_char($filename);
if (PREFIX_IMAGE_FILENAME_WITH_UID) {
$filename = uniqid('') . '_' . $filename;
}
// We always prefix user photos with user ids, so on setting
// api_get_setting('split_users_upload_directory') === 'true'
// the correspondent directories to be found successfully.
$filename = $user_id . '_' . $filename;
}
// Storing the new photos in 4 versions with various sizes.
$small = self::resize_picture($source_file, 22);
$medium = self::resize_picture($source_file, 85);
$normal = self::resize_picture($source_file, 200);
$big = new Image($source_file);
// This is the original picture.
$ok = $small && $small->send_image($path . 'small_' . $filename) && $medium && $medium->send_image($path . 'medium_' . $filename) && $normal && $normal->send_image($path . $filename) && $big && $big->send_image($path . 'big_' . $filename);
return $ok ? $filename : false;
}
示例4: upload_image
/**
* Uploads an author image to the upload/learning_path/images directory
* @param array The image array, coming from the $_FILES superglobal
* @return boolean True on success, false on error
*/
public function upload_image($image_array)
{
$image_moved = false;
if (!empty($image_array['name'])) {
$upload_ok = FileManager::process_uploaded_file($image_array);
$has_attachment = true;
} else {
$image_moved = true;
}
if ($upload_ok) {
if ($has_attachment) {
$courseDir = api_get_course_path() . '/upload/learning_path/images';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$updir = $sys_course_path . $courseDir;
// Try to add an extension to the file if it hasn't one.
$new_file_name = FileManager::add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
if (!FileManager::filter_extension($new_file_name)) {
//Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
$image_moved = false;
} else {
$file_extension = explode('.', $image_array['name']);
$file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
$filename = uniqid('');
$new_file_name = $filename . '.' . $file_extension;
$new_path = $updir . '/' . $new_file_name;
// Resize the image.
$temp = new Image($image_array['tmp_name']);
$picture_infos = $temp->get_image_info();
if ($picture_infos['width'] > 104) {
$thumbwidth = 104;
} else {
$thumbwidth = $picture_infos['width'];
}
if ($picture_infos['height'] > 96) {
$new_height = 96;
} else {
$new_height = $picture_infos['height'];
}
$temp->resize($thumbwidth, $new_height, 0);
$result = $temp->send_image($new_path);
// Storing the image filename.
if ($result) {
$image_moved = true;
$this->set_preview_image($new_file_name);
//Resize to 64px to use on course homepage
$temp->resize(64, 64, 0);
$temp->send_image($updir . '/' . $filename . '.64.' . $file_extension);
return true;
}
}
}
}
return false;
}
示例5: foreach
}
$tableRows = $objSkill->listUsersWhoAchieved($selectedSkill, $coursesFilter);
break;
}
foreach ($tableRows as &$row) {
$row['completeName'] = api_get_person_name($row['firstname'], $row['lastname']);
$row['achievedAt'] = api_format_date($row['acquired_skill_at'], DATE_FORMAT_NUMBER);
$row['courseImage'] = Display::return_icon('course.png', null, null, ICON_SIZE_MEDIUM, null, true);
$imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
if (file_exists($imageSysPath)) {
$thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
$thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $row['c_directory']);
if (!file_exists($thumbSysPath)) {
$courseImageThumb = new Image($imageSysPath);
$courseImageThumb->resize(32);
$courseImageThumb->send_image($thumbSysPath);
}
$row['courseImage'] = $thumbWebPath;
}
}
$tplPath = 'skill/drh_report.html.twig';
$tpl->addGlobal('action', $action);
$tpl->addGlobal('courses', $courses);
$tpl->addGlobal('skills', $skills);
$tpl->addGlobal('selectedCourse', $selectedCourse);
$tpl->addGlobal('selectedSkill', $selectedSkill);
$tpl->addGlobal('reportTitle', $reportTitle);
}
}
}
$tpl->addGlobal('rows', $tableRows);
示例6: upload_watermark
/**
* Uploads the pdf watermark in the main/default_course_document directory or in the course directory
* @param string $filename filename
* @param string $source_file path of the file
* @param string $course_code
* @return mixed web path of the file if sucess, false otherwise
*/
public function upload_watermark($filename, $source_file, $course_code = null)
{
if (!empty($course_code) && api_get_setting('pdf_export_watermark_by_course') == 'true') {
$course_info = api_get_course_info($course_code);
$store_path = api_get_path(SYS_COURSE_PATH).$course_info['path']; // course path
$web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/pdf_watermark.png';
} else {
$store_path = api_get_path(SYS_CODE_PATH).'default_course_document/images'; // course path
$web_path = api_get_path(WEB_CODE_PATH).'default_course_document/images/'.api_get_current_access_url_id().'_pdf_watermark.png';
}
$course_image = $store_path.'/'.api_get_current_access_url_id().'_pdf_watermark.png';
$extension = strtolower(substr(strrchr($filename, '.'), 1));
$result = false;
if (file_exists($course_image)) {
@unlink($course_image);
}
$my_image = new Image($source_file);
$result = $my_image->send_image($course_image, -1, 'png');
if ($result) {
$result = $web_path;
}
return $result;
}
示例7: update_course_picture
/**
* Update course picture
* @param string Course code
* @param string File name
* @param string The full system name of the image from which course picture will be created.
* @param string $cropParameters Optional string that contents "x,y,width,height" of a cropped image format
* @return bool Returns the resulting. In case of internal error or negative validation returns FALSE.
*/
public static function update_course_picture($course_code, $filename, $source_file = null, $cropParameters = null)
{
$course_info = api_get_course_info($course_code);
// course path
$store_path = api_get_path(SYS_COURSE_PATH) . $course_info['path'];
// image name for courses
$course_image = $store_path . '/course-pic.png';
$course_medium_image = $store_path . '/course-pic85x85.png';
if (file_exists($course_image)) {
unlink($course_image);
}
if (file_exists($course_medium_image)) {
unlink($course_medium_image);
}
//Crop the image to adjust 4:3 ratio
$image = new Image($source_file);
$image->crop($cropParameters);
//Resize the images in two formats
$medium = new Image($source_file);
$medium->resize(85);
$medium->send_image($course_medium_image, -1, 'png');
$normal = new Image($source_file);
$normal->resize(300);
$normal->send_image($course_image, -1, 'png');
$result = $medium && $normal;
return $result ? $result : false;
}
示例8: updateTool
/**
* @param int $id
* @param int $courseId
* @param int $sessionId
* @param $values
*/
public static function updateTool($id, $values)
{
$table = Database::get_course_table(TABLE_TOOL_LIST);
$params = ['name' => $values['name'], 'link' => $values['link'], 'target' => $values['target'], 'visibility' => $values['visibility'], 'description' => $values['description']];
if (isset($_FILES['icon']['size']) && $_FILES['icon']['size'] !== 0) {
$dir = self::getCustomSysIconPath();
// Resize image if it is larger than 64px
$temp = new Image($_FILES['icon']['tmp_name']);
$picture_infos = $temp->get_image_info();
if ($picture_infos['width'] > 64) {
$thumbwidth = 64;
} else {
$thumbwidth = $picture_infos['width'];
}
if ($picture_infos['height'] > 64) {
$new_height = 64;
} else {
$new_height = $picture_infos['height'];
}
$temp->resize($thumbwidth, $new_height, 0);
//copy the image to the course upload folder
$path = $dir . $_FILES['icon']['name'];
$result = $temp->send_image($path);
$temp = new Image($path);
$r = $temp->convert2bw();
$ext = pathinfo($path, PATHINFO_EXTENSION);
$bwPath = substr($path, 0, -(strlen($ext) + 1)) . '_na.' . $ext;
if ($r === false) {
error_log('Conversion to B&W of ' . $path . ' failed in ' . __FILE__ . ' at line ' . __LINE__);
} else {
$temp->send_image($bwPath);
$iconName = $_FILES['icon']['name'];
$params['custom_icon'] = $iconName;
}
}
Database::update($table, $params, [' iid = ?' => [$id]]);
}
示例9: add_edit_template
/**
* Add (or edit) a template. This function displays the form and also takes
* care of uploading the image and storing the information in the database
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
* @version August 2008
* @since Dokeos 1.8.6
*/
function add_edit_template()
{
// Initialize the object.
$id = isset($_GET['id']) ? '&id=' . Security::remove_XSS($_GET['id']) : '';
$form = new FormValidator('template', 'post', 'settings.php?category=Templates&action=' . Security::remove_XSS($_GET['action']) . $id);
// Setting the form elements: the header.
if ($_GET['action'] == 'add') {
$title = get_lang('AddTemplate');
} else {
$title = get_lang('EditTemplate');
}
$form->addElement('header', '', $title);
// Setting the form elements: the title of the template.
$form->addText('title', get_lang('Title'), false);
// Setting the form elements: the content of the template (wysiwyg editor).
$form->addHtmlEditor('template_text', get_lang('Text'), false, false, array('ToolbarSet' => 'AdminTemplates', 'Width' => '100%', 'Height' => '400'));
// Setting the form elements: the form to upload an image to be used with the template.
$form->addElement('file', 'template_image', get_lang('Image'), '');
// Setting the form elements: a little bit information about the template image.
$form->addElement('static', 'file_comment', '', get_lang('TemplateImageComment100x70'));
// Getting all the information of the template when editing a template.
if ($_GET['action'] == 'edit') {
// Database table definition.
$table_system_template = Database::get_main_table('system_template');
$sql = "SELECT * FROM {$table_system_template} WHERE id = " . intval($_GET['id']) . "";
$result = Database::query($sql);
$row = Database::fetch_array($result);
$defaults['template_id'] = intval($_GET['id']);
$defaults['template_text'] = $row['content'];
// Forcing get_lang().
$defaults['title'] = get_lang($row['title']);
// Adding an extra field: a hidden field with the id of the template we are editing.
$form->addElement('hidden', 'template_id');
// Adding an extra field: a preview of the image that is currently used.
if (!empty($row['image'])) {
$form->addElement('static', 'template_image_preview', '', '<img src="' . api_get_path(WEB_APP_PATH) . 'home/default_platform_document/template_thumb/' . $row['image'] . '" alt="' . get_lang('TemplatePreview') . '"/>');
} else {
$form->addElement('static', 'template_image_preview', '', '<img src="' . api_get_path(WEB_APP_PATH) . 'home/default_platform_document/template_thumb/noimage.gif" alt="' . get_lang('NoTemplatePreview') . '"/>');
}
// Setting the information of the template that we are editing.
$form->setDefaults($defaults);
}
// Setting the form elements: the submit button.
$form->addButtonSave(get_lang('Ok'), 'submit');
// Setting the rules: the required fields.
$form->addRule('template_image', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('template_text', get_lang('ThisFieldIsRequired'), 'required');
// if the form validates (complies to all rules) we save the information, else we display the form again (with error message if needed)
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
// Exporting the values.
$values = $form->exportValues();
// Upload the file.
if (!empty($_FILES['template_image']['name'])) {
$upload_ok = process_uploaded_file($_FILES['template_image']);
if ($upload_ok) {
// Try to add an extension to the file if it hasn't one.
$new_file_name = add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']);
// The upload directory.
$upload_dir = api_get_path(SYS_APP_PATH) . 'home/default_platform_document/template_thumb/';
// Create the directory if it does not exist.
if (!is_dir($upload_dir)) {
mkdir($upload_dir, api_get_permissions_for_new_directories());
}
// Resize the preview image to max default and upload.
$temp = new Image($_FILES['template_image']['tmp_name']);
$picture_info = $temp->get_image_info();
$max_width_for_picture = 100;
if ($picture_info['width'] > $max_width_for_picture) {
$temp->resize($max_width_for_picture);
}
$temp->send_image($upload_dir . $new_file_name);
}
}
// Store the information in the database (as insert or as update).
$table_system_template = Database::get_main_table('system_template');
if ($_GET['action'] == 'add') {
$content_template = Security::remove_XSS($values['template_text'], COURSEMANAGERLOWSECURITY);
$params = ['title' => $values['title'], 'content' => $content_template, 'image' => $new_file_name];
Database::insert($table_system_template, $params);
// Display a feedback message.
Display::display_confirmation_message(get_lang('TemplateAdded'));
echo '<a href="settings.php?category=Templates&action=add">' . Display::return_icon('new_template.png', get_lang('AddTemplate'), '', ICON_SIZE_MEDIUM) . '</a>';
} else {
$content_template = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body>' . Database::escape_string($values['template_text']) . '</body>';
$sql = "UPDATE {$table_system_template} set title = '" . Database::escape_string($values['title']) . "', content = '" . $content_template . "'";
if (!empty($new_file_name)) {
$sql .= ", image = '" . Database::escape_string($new_file_name) . "'";
}
$sql .= " WHERE id = " . intval($_GET['id']) . "";
//.........这里部分代码省略.........
示例10: sendWallMessageAttachmentFile
/**
* Send File attachment (jpg,png)
* @author Anibal Copitan
* @param int $userId id user
* @param array $fileAttach
* @param int $messageId id message (relation with main message)
* @param string $fileComment description attachment file
* @return bool
*/
public static function sendWallMessageAttachmentFile($userId, $fileAttach, $messageId, $fileComment = '')
{
$tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
// create directory
$social = '/social/';
$pathMessageAttach = UserManager::getUserPathById($userId, 'system') . 'message_attachments' . $social;
$safeFileComment = Database::escape_string($fileComment);
$safeFileName = Database::escape_string($fileAttach['name']);
$extension = strtolower(substr(strrchr($safeFileName, '.'), 1));
$allowedTypes = api_get_supported_image_extensions();
if (!in_array($extension, $allowedTypes)) {
$flag = false;
} else {
$newFileName = uniqid('') . '.' . $extension;
if (!file_exists($pathMessageAttach)) {
@mkdir($pathMessageAttach, api_get_permissions_for_new_directories(), true);
}
$newPath = $pathMessageAttach . $newFileName;
if (is_uploaded_file($fileAttach['tmp_name'])) {
@copy($fileAttach['tmp_name'], $newPath);
}
$small = self::resize_picture($newPath, IMAGE_WALL_SMALL_SIZE);
$medium = self::resize_picture($newPath, IMAGE_WALL_MEDIUM_SIZE);
$big = new Image($newPath);
$ok = $small && $small->send_image($pathMessageAttach . IMAGE_WALL_SMALL . '_' . $newFileName) && $medium && $medium->send_image($pathMessageAttach . IMAGE_WALL_MEDIUM . '_' . $newFileName) && $big && $big->send_image($pathMessageAttach . IMAGE_WALL_BIG . '_' . $newFileName);
// Insert
$newFileName = $social . $newFileName;
$params = ['filename' => $safeFileName, 'comment' => $safeFileComment, 'path' => $newFileName, 'message_id' => $messageId, 'size' => $fileAttach['size']];
Database::insert($tbl_message_attach, $params);
$flag = true;
}
return $flag;
}
示例11: update_course_picture
/**
* Update course picture
* @param string Course code
* @param string File name
* @param string The full system name of the image from which course picture will be created.
* @return bool Returns the resulting. In case of internal error or negative validation returns FALSE.
*/
public static function update_course_picture($course_code, $filename, $source_file = null)
{
$course_info = api_get_course_info($course_code);
$store_path = api_get_path(SYS_COURSE_PATH) . $course_info['path'];
// course path
$course_image = $store_path . '/course-pic.png';
// image name for courses
$course_medium_image = $store_path . '/course-pic85x85.png';
//$extension = strtolower(substr(strrchr($filename, '.'), 1));
if (file_exists($course_image)) {
@unlink($course_image);
}
if (file_exists($course_medium_image)) {
@unlink($course_medium_image);
}
$my_course_image = new Image($source_file);
$result = $my_course_image->send_image($course_image, -1, 'png');
//Redimension image to 100x85
if ($result) {
$medium = new Image($course_image);
//$picture_infos = $medium->get_image_size();
$medium->resize(100, 85, 0, false);
$medium->send_image($store_path . '/course-pic85x85.png', -1, 'png');
}
return $result;
}
示例12: round
if (empty($thumbwidth) or $thumbwidth == 0) {
$thumbwidth = 150;
}
$new_height = ($picture_infos[0] > 0) ? round(($thumbwidth / $picture_infos[0]) * $picture_infos[1]) : 0;
$temp->resize($thumbwidth, $new_height, 0);
$type = $picture_infos[2];
// Original picture
$big_temp = new Image($image_repository);
switch (!empty($type)) {
case 2 : $temp->send_image('JPG', $picture_location);
$big_temp->send_image('JPG', $big_picture_location);
break;
case 3 : $temp->send_image('PNG', $picture_location);
$big_temp->send_image('JPG', $big_picture_location);
break;
case 1 : $temp->send_image('GIF', $picture_location);
$big_temp->send_image('JPG', $big_picture_location);
break;
}
if ($image_repository == $dir . $file) {
@unlink($image_repository);
}
}
}
}
// Filling the access_url_rel_session table with access_url_id by default = 1
示例13: unlink
$existsBadgesDirectory = is_dir($badgePath);
if (!$existsBadgesDirectory) {
$existsBadgesDirectory = api_create_protected_dir('badges', api_get_path(SYS_UPLOAD_PATH));
}
if ($existsBadgesDirectory) {
if (!empty($skill['icon'])) {
$iconFileAbsolutePath = $badgePath . $skill['icon'];
if (Security::check_abs_path($iconFileAbsolutePath, $badgePath)) {
unlink($badgePath . $skill['icon']);
}
}
$skillImagePath = sprintf("%s%s.png", $badgePath, $fileName);
$skillImage = new Image($_FILES['image']['tmp_name']);
$skillImage->send_image($skillImagePath, -1, 'png');
$skillThumbPath = sprintf("%s%s-small.png", $badgePath, $fileName);
$skillImageThumb = new Image($skillImagePath);
$skillImageThumb->resize(ICON_SIZE_BIG, ICON_SIZE_BIG);
$skillImageThumb->send_image($skillThumbPath);
$params['icon'] = sprintf("%s.png", $fileName);
} else {
Session::write('errorMessage', get_lang('UplUnableToSaveFile'));
}
}
$objSkill->update($params);
header('Location: ' . api_get_path(WEB_CODE_PATH) . 'admin/skill_badge_list.php');
exit;
}
$interbreadcrumb = array(array('url' => api_get_path(WEB_CODE_PATH) . 'admin/index.php', 'name' => get_lang('Administration')), array('url' => api_get_path(WEB_CODE_PATH) . 'admin/skill_badge.php', 'name' => get_lang('Badges')), array('url' => '#', 'name' => get_lang('CreateBadge')));
$toolbar = Display::toolbarButton(get_lang('ManageSkills'), api_get_path(WEB_CODE_PATH) . 'admin/skill_list.php', 'list', 'primary', ['title' => get_lang('ManageSkills')]);
echo $toolbar;
echo Container::getTemplating()->render('@template_style/skill/badge_create.html.twig', ['skill' => $skill]);
示例14: make_lp
public function make_lp($files = array())
{
global $_course;
$previous = 0;
$i = 0;
if (!is_dir($this->base_work_dir.$this->created_dir))
return false;
foreach ($files as $file) {
/* '||' is used as separator between fields:
slide name (with accents) || file name (without accents) || all slide text (to be indexed).
*/
list($slide_name, $file_name, $slide_body) = explode('||', $file);
// Filename is utf8 encoded, but when we decode, some chars are not translated (like quote ’).
// so we remove these chars by translating it in htmlentities and the reconvert it in want charset.
$slide_name = api_htmlentities($slide_name, ENT_COMPAT, $this->original_charset);
$slide_name = str_replace('’', '\'', $slide_name);
$slide_name = api_convert_encoding($slide_name, api_get_system_encoding(), $this->original_charset);
$slide_name = api_html_entity_decode($slide_name, ENT_COMPAT, api_get_system_encoding());
if ($this->take_slide_name === true) {
$slide_name = str_replace('_', ' ', $slide_name);
$slide_name = api_ucfirst($slide_name);
} else {
$slide_name = 'slide'.str_repeat('0', 2 - strlen($i)).$i;
}
$i++;
// Add the png to documents.
$document_id = add_document(
$_course,
$this->created_dir.'/'.urlencode($file_name),
'file',
filesize($this->base_work_dir.$this->created_dir.'/'.$file_name),
$slide_name
);
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$document_id,
'DocumentAdded',
api_get_user_id(),
0,
0,
null,
null,
api_get_session_id()
);
// Generating the thumbnail.
$image = $this->base_work_dir.$this->created_dir .'/'. $file_name;
$pattern = '/(\w+)\.png$/';
$replacement = '${1}_thumb.png';
$thumb_name = preg_replace($pattern, $replacement, $file_name);
// Calculate thumbnail size.
$image_size = api_getimagesize($image);
$width = $image_size['width'];
$height = $image_size['height'];
$thumb_width = 300;
$thumb_height = floor($height * ($thumb_width / $width));
$my_new_image = new Image($image);
$my_new_image->resize($thumb_width, $thumb_height);
$my_new_image->send_image($this->base_work_dir.$this->created_dir .'/'. $thumb_name, -1, 'png');
// Adding the thumbnail to documents.
$document_id_thumb = add_document(
$_course,
$this->created_dir.'/'.urlencode($thumb_name),
'file',
filesize($this->base_work_dir.$this->created_dir.'/'.$thumb_name),
$slide_name
);
api_item_property_update($_course, TOOL_THUMBNAIL, $document_id_thumb, 'DocumentAdded', api_get_user_id(), 0, 0);
// Create an html file.
$html_file = $file_name.'.html';
$fp = fopen($this->base_work_dir.$this->created_dir.'/'.$html_file, 'w+');
$slide_src = api_get_path(REL_COURSE_PATH).$_course['path'].'/document/'.$this->created_dir.'/'.utf8_encode($file_name);
$slide_src = str_replace('//', '/', $slide_src);
fwrite($fp,
'<html>
<head>
</head>
<body>
<img src="'.$slide_src.'" />
</body>
</html>'); // This indentation is to make the generated html files to look well.
fclose($fp);
$document_id = add_document(
$_course,
//.........这里部分代码省略.........
示例15: Image
// Upload the file
if (!empty($_FILES['template_image']['name'])) {
$upload_ok = process_uploaded_file($_FILES['template_image']);
if ($upload_ok) {
// Try to add an extension to the file if it hasn't one
$new_file_name = $courseInfo['code'] . '-' . add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']);
// Upload dir
$upload_dir = api_get_path(SYS_COURSE_PATH) . $courseInfo['directory'] . '/upload/template_thumbnails/';
// Resize image to max default and end upload
$temp = new Image($_FILES['template_image']['tmp_name']);
$picture_info = $temp->get_image_info();
$max_width_for_picture = 100;
if ($picture_info['width'] > $max_width_for_picture) {
$temp->resize($max_width_for_picture);
}
$temp->send_image($upload_dir . $new_file_name);
}
}
DocumentManager::set_document_as_template($title, '', $document_id_for_template, $course_code, $user_id, $new_file_name);
Display::addFlash(Display::return_message(get_lang('DocumentSetAsTemplate'), 'confirmation'));
}
if (isset($_GET['remove_as_template'])) {
$document_id_for_template = intval($_GET['remove_as_template']);
$user_id = api_get_user_id();
DocumentManager::unset_document_as_template($document_id_for_template, $course_code, $user_id);
Display::addFlash(Display::return_message(get_lang('DocumentUnsetAsTemplate'), 'confirmation'));
}
}
// END ACTION MENU
// Attach certificate in the gradebook
if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_certificate']) && $_GET['set_certificate'] == strval(intval($_GET['set_certificate']))) {