本文整理汇总了PHP中convert_image函数的典型用法代码示例。如果您正苦于以下问题:PHP convert_image函数的具体用法?PHP convert_image怎么用?PHP convert_image使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了convert_image函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: directory_thumb_mirror
/**
* Create filename-mirrored thumbnails for the given directory stub (mirrors stub/foo with stub_thumbs/foo).
*
* @param string Directory to mirror
*/
function directory_thumb_mirror($dir)
{
require_code('images');
$full = get_custom_file_base() . '/uploads/' . $dir;
$dh = @opendir($full);
if ($dh !== false) {
while (($file = readdir($dh)) !== false) {
$target = get_custom_file_base() . '/' . $dir . '_thumbs/' . $file;
if (!file_exists($target) && is_image($full . '/' . $file)) {
require_code('images');
convert_image($full . '/' . $file, $target, -1, -1, intval(get_option('thumb_width')));
}
}
}
closedir($dh);
}
示例2: constrain_gallery_image_to_max_size
/**
* Make sure the detailed image file is not bigger than the defined box width.
*
* @param PATH The path to the image file
* @param string The original filename of the image
* @param integer The box width
*/
function constrain_gallery_image_to_max_size($file_path, $filename, $box_width)
{
// We can't watermark an image we can't save
require_code('images');
if (!is_saveable_image($filename)) {
return;
}
if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
convert_image($file_path, $file_path, -1, -1, $box_width, false, get_file_extension($filename), true, true);
}
}
示例3: ensure_thumbnail
/**
* Take some image/thumbnail info, and if needed make and caches a thumbnail, and return a thumb url whatever the situation.
*
* @param URLPATH The full URL to the image which will-be/is thumbnailed
* @param URLPATH The URL to the thumbnail (blank: no thumbnail yet)
* @param ID_TEXT The directory, relative to the ocPortal uploads directory, where the thumbnails are stored. MINUS "_thumbs"
* @param ID_TEXT The name of the table that is storing what we are doing the thumbnail for
* @param AUTO_LINK The ID of the table record that is storing what we are doing the thumbnail for
* @param ID_TEXT The name of the table field where thumbnails are saved
* @param ?integer The thumbnail width to use (NULL: default)
* @return URLPATH The URL to the thumbnail
*/
function ensure_thumbnail($full_url, $thumb_url, $thumb_dir, $table, $id, $thumb_field_name = 'thumb_url', $thumb_width = NULL)
{
if (is_null($thumb_width)) {
$thumb_width = intval(get_option('thumb_width'));
}
if (get_option('is_on_gd') == '0' || !function_exists('imagetypes') || $full_url == '') {
if (url_is_local($thumb_url) && $thumb_url != '') {
return get_custom_base_url() . '/' . $thumb_url;
}
return $thumb_url;
}
if ($thumb_url != '') {
if (url_is_local($thumb_url)) {
$thumb_path = get_custom_file_base() . '/' . rawurldecode($thumb_url);
if (!file_exists($thumb_path)) {
$from = str_replace(' ', '%20', $full_url);
if (url_is_local($from)) {
$from = get_custom_base_url() . '/' . $from;
}
if (is_video($from)) {
require_code('galleries2');
create_video_thumb($full_url, $thumb_path);
} else {
convert_image($from, $thumb_path, intval($thumb_width), -1, -1, false);
}
}
return get_custom_base_url() . '/' . $thumb_url;
}
return $thumb_url;
}
$url_parts = explode('/', $full_url);
$i = 0;
$_file = $url_parts[count($url_parts) - 1];
$dot_pos = strrpos($_file, '.');
$ext = substr($_file, $dot_pos + 1);
if (!is_saveable_image($_file)) {
$ext = 'png';
}
$_file = preg_replace('#[^\\w]#', 'x', substr($_file, 0, $dot_pos));
$thumb_path = '';
do {
$file = rawurldecode($_file) . ($i == 0 ? '' : strval($i));
$thumb_path = get_custom_file_base() . '/uploads/' . $thumb_dir . '_thumbs/' . $file . '.' . $ext;
$i++;
} while (file_exists($thumb_path));
$thumb_url = 'uploads/' . $thumb_dir . '_thumbs/' . rawurlencode($file) . '.' . $ext;
if (substr($table, 0, 2) == 'f_' && get_forum_type() == 'ocf') {
$GLOBALS['FORUM_DB']->query_update($table, array($thumb_field_name => $thumb_url), array('id' => $id), '', 1);
} else {
$GLOBALS['SITE_DB']->query_update($table, array($thumb_field_name => $thumb_url), array('id' => $id), '', 1);
}
$from = str_replace(' ', '%20', $full_url);
if (url_is_local($from)) {
$from = get_custom_base_url() . '/' . $from;
}
if (!file_exists($thumb_path)) {
if (is_video($from)) {
require_code('galleries2');
create_video_thumb($full_url, $thumb_path);
} else {
convert_image($from, $thumb_path, intval($thumb_width), -1, -1, false);
}
}
return get_custom_base_url() . '/' . $thumb_url;
}
示例4: convert_image
$ret = convert_image($filename, $output_filename, $res, $is_thumbnail);
if ($ret) {
echo "Writing (" . $res . ")\t\t\t: success\n<br>\n";
$convert_success = true;
} else {
echo "Writing (" . $res . ")\t\t\t: failed\n<br>\n";
echo "Aborting...\n<br>\n";
$convert_success = false;
break;
}
}
// convert image to JPEG with original resolution
if ($convert_success) {
$output_filename = $tmpdir . 'cache' . DIRECTORY_SEPARATOR . $tmpid . '.jpg';
$res = $img_data['width'] . 'x' . $img_data['height'];
$ret = convert_image($filename, $output_filename, $res, false);
if ($ret) {
echo "Writing (" . $res . ")\t\t\t: success\n<br>\n";
$convert_success = true;
} else {
echo "Writing (" . $res . ")\t\t\t: failed\n<br>\n";
echo "Aborting...\n<br>\n";
$convert_success = false;
}
}
if ($convert_success) {
// we have all necessary files now, so we get a correct id and move the files
//
// in unlikely cases this section will cause trouble, i.e. when someone gets
// a new id while we are copying and before we insert into the database
echo "\n<br>\nCopying generated image versions to their correct locations: \n<br><br>\n";
示例5: process_image_directory
//.........这里部分代码省略.........
$errorstring .= "Directory: " . $output_dir . "\n<br>\n";
die($errorstring);
}
// use a temporary directory, where we can store the converted files until we have
// completed the task for all resolutions.
// we will move files from there into the correct directory later
$tmpdir = $config['imageTmp'];
if (!is_dir($tmpdir)) {
$errorstring = "Could not find temporary directory! \n<br>\n";
$errorstring .= "Path: " . $tmpdir . "\n<br>\n";
die($errorstring);
}
// check if we already have a cache directory structure, otherwise create
$ret = check_dir($tmpdir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR, true, true, 0755);
if (!$ret) {
$errorstring = "Temporary directory cache does not exist or is not writable! \n<br>\n";
die($errorstring);
}
// generate image in all necessary resolutions
// you can skip resolutions by changing the array at this point
$resolutions = $resolutions_available;
foreach ($resolutions as $res) {
$ret = check_dir($tmpdir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . $res, true, true, 0755);
if (!$ret) {
$errorstring = "Error creating temporary directory cache for resolution: {$res}! \n<br>\n";
die($errorstring);
}
}
// generate temporary id string
$tmpid = generate_random_string();
// carry out conversion steps
echo "\n<br>\n<em>Generating image versions for all resolutions:</em>\n<br><br>\n";
if ($config['imagick_mode'] == 'fast') {
$ret = convert_image_batch($filename, $tmpdir . 'cache', $tmpid, $resolutions);
if ($ret) {
echo "Generating images (batch mode)\t\t\t: success\n<br>\n";
$convert_success = true;
} else {
echo "Generating images (batch mode)\t\t\t: failed\n<br>\n";
echo "Aborting...\n<br>\n";
$convert_success = false;
}
} else {
// convert image to JPG at 1600x1200 as a base for the following conversion
$baseimage_filename = $tmpdir . 'cache' . DIRECTORY_SEPARATOR . $tmpid . '.jpg';
$res = '1600x1200';
$ret = convert_image($filename, $baseimage_filename, $res, false);
if ($ret) {
echo "Generating base image\t\t\t: success\n<br>\n";
$convert_success = true;
} else {
echo "Generating base image\t\t\t: failed\n<br>\n";
echo "Aborting...\n<br>\n";
$convert_success = false;
}
// the following lines will generate a JPG-version of your original image
// uncomment them, if you need it (requires additional computation time)
/*
if ($convert_success)
{
$output_filename = $tmpdir.'cache'.DIRECTORY_SEPARATOR.$tmpid.'.jpg';
$res = $img_data['width'].'x'.$img_data['height'];
$ret = convert_image($filename,$output_filename,$res, false);
示例6: edit_actualisation
/**
* Standard aed_module edit actualiser.
*
* @param ID_TEXT The entry being edited
*/
function edit_actualisation($_id)
{
$id = intval($_id);
$validated = post_param_integer('validated', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
$news_article = post_param('post', STRING_MAGIC_NULL);
if (post_param('main_news_category') != 'personal') {
$main_news_category = post_param_integer('main_news_category', INTEGER_MAGIC_NULL);
} else {
warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
}
$news_category = array();
if (array_key_exists('news_category', $_POST)) {
foreach ($_POST['news_category'] as $val) {
$news_category[] = intval($val);
}
}
$allow_rating = post_param_integer('allow_rating', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
$allow_comments = post_param_integer('allow_comments', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
$allow_trackbacks = post_param_integer('allow_trackbacks', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
$notes = post_param('notes', STRING_MAGIC_NULL);
$this->donext_type = $main_news_category;
if (!fractional_edit()) {
$urls = get_url('', 'file', 'uploads/grepimages', 0, OCP_UPLOAD_IMAGE);
$url = $urls[0];
if ($url != '' && function_exists('imagecreatefromstring')) {
convert_image(get_base_url() . '/' . $url, get_file_base() . '/uploads/grepimages/' . basename(rawurldecode($url)), -1, -1, intval(get_option('thumb_width')), true, NULL, false, true);
}
if ($url == '' && post_param_integer('file_unlink', 0) != 1) {
$url = NULL;
}
} else {
$url = STRING_MAGIC_NULL;
}
$owner = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'nc_owner', array('id' => $main_news_category));
// null_ok in case somehow category setting corrupted
if (!is_null($owner) && $owner != get_member()) {
check_specific_permission('can_submit_to_others_categories', array('news', $main_news_category), NULL, 'cms_news');
}
$schedule = get_input_date('schedule');
$add_time = is_null($schedule) ? mixed() : $schedule;
if (addon_installed('calendar') && has_specific_permission(get_member(), 'scheduled_publication_times')) {
require_code('calendar2');
$schedule_code = ':$GLOBALS[\'SITE_DB\']->query_update(\'news\',array(\'date_and_time\'=>$GLOBALS[\'event_timestamp\'],\'validated\'=>1),array(\'id\'=>' . strval($id) . '),\'\',1);';
$past_event = $GLOBALS['SITE_DB']->query_value_null_ok('calendar_events e LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON e.e_content=t.id', 'e.id', array('text_original' => $schedule_code));
require_code('calendar');
if (!is_null($past_event)) {
delete_calendar_event($past_event);
}
if (!is_null($schedule) && $schedule > time()) {
$validated = 0;
$start_year = post_param_integer('schedule_year');
$start_month = post_param_integer('schedule_month');
$start_day = post_param_integer('schedule_day');
$start_hour = post_param_integer('schedule_hour');
$start_minute = post_param_integer('schedule_minute');
$event_id = add_calendar_event(db_get_first_id(), 'none', NULL, 0, do_lang('PUBLISH_NEWS', 0, post_param('title')), $schedule_code, 3, 0, $start_year, $start_month, $start_day, $start_hour, $start_minute);
regenerate_event_reminder_jobs($event_id, true);
}
}
$title = post_param('title', STRING_MAGIC_NULL);
if ($validated == 1 && $main_news_category != INTEGER_MAGIC_NULL && $GLOBALS['SITE_DB']->query_value('news', 'validated', array('id' => intval($id))) == 0) {
$is_blog = true;
$submitter = $GLOBALS['SITE_DB']->query_value('news', 'submitter', array('id' => $id));
$activity_title = $is_blog ? 'news:ACTIVITY_ADD_NEWS_BLOG' : 'news:ACTIVITY_ADD_NEWS';
$activity_title_validate = $is_blog ? 'news:ACTIVITY_VALIDATE_NEWS_BLOG' : 'news:ACTIVITY_VALIDATE_NEWS';
if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'news')) {
// NB: no category permission check, as syndication choice was explicit, and news categorisation is a bit more complex
syndicate_described_activity($submitter != get_member() ? $activity_title_validate : $activity_title, $title, '', '', '_SEARCH:news:view:' . strval($id), '', '', 'news', 1, NULL, true);
}
}
edit_news(intval($id), $title, post_param('news', STRING_MAGIC_NULL), post_param('author', STRING_MAGIC_NULL), $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $news_article, $main_news_category, $news_category, post_param('meta_keywords', STRING_MAGIC_NULL), post_param('meta_description', STRING_MAGIC_NULL), $url, $add_time);
}
示例7: get_url
//.........这里部分代码省略.........
} else {
warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format($max_size)));
}
} elseif ($_FILES[$attach_name]['error'] == 2) {
if ($accept_errors) {
attach_message(do_lang_tempcode('FILE_TOO_BIG_QUOTA', integer_format($max_size)), 'warn');
return array('', '', '', '');
} else {
warn_exit(do_lang_tempcode('FILE_TOO_BIG_QUOTA', integer_format($max_size)));
}
} elseif ($_FILES[$attach_name]['error'] == 3 || $_FILES[$attach_name]['error'] == 4 || $_FILES[$attach_name]['error'] == 6 || $_FILES[$attach_name]['error'] == 7) {
attach_message(do_lang_tempcode('ERROR_UPLOADING_' . strval($_FILES[$attach_name]['error'])), 'warn');
return array('', '', '', '');
} else {
warn_exit(do_lang_tempcode('ERROR_UPLOADING_' . strval($_FILES[$attach_name]['error'])));
}
}
$url[0] = '';
$url[1] = '';
$is_image = false;
}
$out[0] = $url[0];
$out[2] = $url[1];
// Generate thumbnail if needed
if ($make_thumbnail && $url[0] != '' && $is_image) {
if (array_key_exists($thumb_attach_name, $_FILES) && (is_uploaded_file($_FILES[$thumb_attach_name]['tmp_name']) || $swf_uploaded_thumb)) {
if ($_FILES[$thumb_attach_name]['size'] > get_max_image_size()) {
if ($accept_errors) {
attach_message(do_lang_tempcode('FILE_TOO_BIG', integer_format(get_max_image_size())), 'warn');
return array('', '', '', '');
} else {
warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format(get_max_image_size())));
}
}
$_thumb = _get_upload_url($thumb_attach_name, $thumb_folder, OCP_UPLOAD_IMAGE, 0, $accept_errors);
$thumb = $_thumb[0];
} elseif (array_key_exists($thumb_specify_name, $_POST)) {
$_thumb = _get_specify_url($thumb_specify_name, $thumb_folder, OCP_UPLOAD_IMAGE, $accept_errors);
$thumb = $_thumb[0];
} else {
$gd = get_option('is_on_gd') == '1' && function_exists('imagetypes');
if ($gd) {
if (!is_saveable_image($url[0])) {
$ext = '.png';
} else {
$ext = '';
}
$file = preg_replace('#[^\\w\\.]#', 'x', basename($url[0]));
$_file = $file;
$place = get_custom_file_base() . '/' . $thumb_folder . '/' . $_file . $ext;
$i = 2;
while (file_exists($place)) {
$_file = strval($i) . $file;
$place = get_custom_file_base() . '/' . $thumb_folder . '/' . $_file . $ext;
$i++;
}
$url_full = url_is_local($url[0]) ? get_custom_base_url() . '/' . $url[0] : $url[0];
convert_image($url_full, $place, -1, -1, intval(get_option('thumb_width')));
$thumb = $thumb_folder . '/' . rawurlencode($_file) . $ext;
} else {
if ($accept_errors) {
attach_message(do_lang_tempcode('GD_THUMB_ERROR'), 'warn');
return array('', '', '', '');
} else {
warn_exit(do_lang_tempcode('GD_THUMB_ERROR'));
}
}
}
$out[1] = $thumb;
} elseif ($make_thumbnail) {
if (array_key_exists($thumb_attach_name, $_FILES) && (is_uploaded_file($_FILES[$thumb_attach_name]['tmp_name']) || $swf_uploaded_thumb)) {
if ($_FILES[$thumb_attach_name]['size'] > get_max_image_size()) {
if ($accept_errors) {
attach_message(do_lang_tempcode('FILE_TOO_BIG', integer_format(get_max_image_size())), 'warn');
return array('', '', '', '');
} else {
warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format(get_max_image_size())));
}
}
$_thumb = _get_upload_url($thumb_attach_name, $thumb_folder, OCP_UPLOAD_IMAGE, 0, $accept_errors);
$thumb = $_thumb[0];
} elseif (array_key_exists($thumb_specify_name, $_POST)) {
$_thumb = _get_specify_url($thumb_specify_name, $thumb_folder, OCP_UPLOAD_IMAGE, $accept_errors);
$thumb = $_thumb[0];
}
if (!is_null($thumb)) {
$out[1] = $thumb;
} else {
$out[1] = '';
}
}
// For reentrance of previews
if ($specify_name != '') {
$_POST[$specify_name] = array_key_exists(0, $out) ? $out[0] : '';
}
if ($thumb_specify_name != '') {
$_POST[$thumb_specify_name] = array_key_exists(1, $out) ? $out[1] : '';
}
return $out;
}
示例8: data_to_disk
/**
* Convert a VB database file to an ocPortal uploaded file (stored on disk).
*
* @param string The file data
* @param string The optimal filename
* @param ID_TEXT The upload type (e.g. ocf_photos)
* @param boolean Whether to create a thumbnail for it
* @param string Thumbnail data (blank: no thumbnail / generate one if asked)
* @param boolean Whether to obfuscate the file type
* @return array A tuple containing the URL, and if requested, the thumbnail
*/
function data_to_disk($data, $filename, $sections, $thumbnail = true, $thumbnail_data = '', $obfuscate = false)
{
if ($filename == '') {
$filetype = '';
if (substr($data, 4, 4) == 'JFIF') {
$filetype = 'jpg';
} elseif (substr($data, 0, 3) == 'GIF') {
$filetype = 'gif';
} elseif (substr($data, 1, 3) == 'PNG') {
$filetype = 'png';
}
if ($filetype != '') {
$filename = uniqid('', true) . '.' . $filetype;
}
}
//if ((substr($filename,-4,4)=='.gif') && ($thumbnail)) $filename.='.png';
if ($filename != '') {
$filename = find_derivative_filename('uploads/' . $sections, $filename);
$path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : '');
$myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : ''))));
if (fwrite($myfile, $data) < strlen($data)) {
warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
}
fclose($myfile);
fix_permissions($path);
sync_file($path);
$url = 'uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : '');
if ($thumbnail_data == '') {
if ($thumbnail) {
$t_filename = $filename;
$thumb_url = 'uploads/' . $sections . '_thumbs/' . find_derivative_filename('_thumbs', $t_filename, true);
require_code('images');
convert_image(get_custom_base_url() . '/' . $url, $thumb_url, -1, -1, intval(get_option('thumb_width')), false, NULL, true);
return array($url, $thumb_url);
} else {
return array($url, '');
}
} else {
$thumb_filename = find_derivative_filename('uploads/' . $sections . '_thumbs', $filename);
$path = get_custom_file_base() . '/uploads/' . $sections . '_thumbs/' . $thumb_filename;
$myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '_thumbs/' . $thumb_filename)));
if (fwrite($myfile, $thumbnail_data) < strlen($thumbnail_data)) {
warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
}
fclose($myfile);
$thumb_url = 'uploads/' . $sections . '/' . $thumb_filename;
fix_permissions($path);
sync_file($path);
return array($url, $thumb_url);
}
}
return array('', '');
}
示例9: import_ocf_member_files
/**
* Standard import function.
*
* @param object The DB connection to import from
* @param string The table prefix the target prefix is using
* @param PATH The base directory we are importing from
*/
function import_ocf_member_files($db, $table_prefix, $file_base)
{
global $STRICT_FILE;
$row_start = 0;
$rows = array();
do {
$query = 'SELECT * FROM ' . $table_prefix . 'members ORDER BY id';
$rows = $db->query($query, 200, $row_start);
foreach ($rows as $row) {
if (import_check_if_imported('member_files', strval($row['id']))) {
continue;
}
$member_id = import_id_remap_get('member', strval($row['id']));
$photo_url = '';
$photo_thumb_url = '';
$rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'member_extra WHERE id=' . strval($row['id']));
if (array_key_exists(0, $rows2)) {
$row2 = $rows2[0];
if ($row2['photo_type'] == 'upload') {
$filename = rawurldecode($row2['photo_location']);
if (file_exists(get_custom_file_base() . '/uploads/ocf_photos/' . $filename) || @rename($file_base . '/uploads/' . $filename, get_custom_file_base() . '/uploads/ocf_photos/' . $filename)) {
$photo_url = 'uploads/ocf_photos/' . $filename;
sync_file($photo_url);
} else {
if ($STRICT_FILE) {
warn_exit(do_lang_tempcode('MISSING_PHOTO', $filename));
}
$photo_url = '';
}
} else {
$photo_url = $row2['photo_location'];
$rrpos = strrpos($photo_url, '/');
$filename = $rrpos === false ? $photo_url : substr($photo_url, $rrpos);
}
if ($photo_url != '' && function_exists('imagecreatefromstring')) {
$photo_thumb_url = 'uploads/ocf_photos_thumbs/' . find_derivative_filename('ocf_photos_thumbs', $filename, true);
require_code('images');
convert_image($photo_url, $photo_thumb_url, -1, -1, intval(get_option('thumb_width')), false, NULL, true);
}
if (either_param('importer') == 'ipb2') {
$row['avatar'] = $row2['avatar_location'];
$row['avatar_type'] = $row2['avatar_type'];
}
}
if (either_param('importer') == 'ipb2') {
if (!array_key_exists('avatar', $row)) {
$row['avatar'] = NULL;
}
}
$avatar_url = '';
switch ($row['avatar']) {
case NULL:
break;
case 'noavatar':
break;
default:
if (substr($row['avatar'], 0, 7) == 'upload:') {
$filename = substr($row['avatar'], 7);
if (file_exists(get_custom_file_base() . '/uploads/ocf_avatars/' . $filename) || @rename($file_base . '/uploads/' . $filename, get_custom_file_base() . '/uploads/ocf_avatars/' . $filename)) {
$avatar_url = 'uploads/ocf_avatars/' . $filename;
sync_file($avatar_url);
} else {
if ($STRICT_FILE) {
warn_exit(do_lang_tempcode('MISSING_AVATAR', $filename));
}
$avatar_url = '';
}
} elseif (url_is_local($row['avatar'])) {
$filename = rawurldecode($row['avatar']);
if (file_exists(get_custom_file_base() . '/uploads/ocf_avatars/' . $filename) || @rename($file_base . '/uploads/' . $filename, get_custom_file_base() . '/uploads/ocf_avatars/' . $filename)) {
$avatar_url = 'uploads/ocf_avatars/' . substr($filename, strrpos($filename, '/'));
sync_file($avatar_url);
} else {
// Try as a pack avatar then
$filename = rawurldecode($row['avatar']);
$striped_filename = str_replace('/', '_', $filename);
if (file_exists(get_custom_file_base() . '/uploads/ocf_avatars/' . $striped_filename) || @rename($file_base . '/style_avatars/' . $filename, get_custom_file_base() . '/uploads/ocf_avatars/' . $striped_filename)) {
$avatar_url = 'uploads/ocf_avatars/' . substr($filename, strrpos($filename, '/'));
sync_file($avatar_url);
} else {
if ($STRICT_FILE) {
warn_exit(do_lang_tempcode('MISSING_AVATAR', $filename));
}
$avatar_url = '';
}
}
} else {
$avatar_url = $row['avatar'];
}
}
$GLOBALS['FORUM_DB']->query_update('f_members', array('m_avatar_url' => $avatar_url, 'm_photo_url' => $photo_url, 'm_photo_thumb_url' => $photo_thumb_url), array('id' => $member_id), '', 1);
import_id_remap_put('member_files', strval($row['id']), 1);
}
//.........这里部分代码省略.........
示例10: _do_tags_comcode
//.........这里部分代码省略.........
} else {
$new_filename = $md5 . '.' . get_file_extension($original_filename);
}
$path = get_custom_file_base() . '/uploads/attachments/' . $new_filename;
$myfile = @fopen($path, 'wb');
if ($myfile === false) {
$temp_tpl = do_template('WARNING_TABLE', array('WARNING' => intelligent_write_error_inline($path)));
break;
}
if (fwrite($myfile, $file) < strlen($file)) {
warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
}
fclose($myfile);
fix_permissions($path);
sync_file($path);
$_size = strlen($file);
$url = 'uploads/attachments/' . $new_filename;
if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
$url = get_custom_base_url() . '/' . $url;
}
// Thumbnail
if ($thumb_url == '') {
require_code('images');
if (is_image($original_filename)) {
$gd = get_option('is_on_gd') == '1' && function_exists('imagetypes');
if ($gd) {
require_code('images');
if (!is_saveable_image($url)) {
$ext = '.png';
} else {
$ext = '.' . get_file_extension($original_filename);
}
$thumb_url = 'uploads/attachments_thumbs/' . $md5 . $ext;
convert_image(get_custom_base_url() . '/' . $url, get_custom_file_base() . '/' . $thumb_url, -1, -1, intval(get_option('thumb_width')), true, NULL, false, true);
if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
$thumb_url = get_custom_base_url() . '/' . $thumb_url;
}
} else {
$thumb_url = $url;
}
}
}
if (addon_installed('galleries')) {
require_code('images');
if (is_video($url) && $connection->connection_read == $GLOBALS['SITE_DB']->connection_read) {
require_code('transcoding');
$url = transcode_video($url, 'attachments', 'a_url', 'a_original_filename', NULL, NULL);
}
}
$attachment = array('a_member_id' => $on_behalf_of_member, 'a_file_size' => $_size, 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $original_filename, 'a_num_downloads' => 0, 'a_last_downloaded_time' => NULL, 'a_add_time' => time());
$attachment['a_description'] = array_key_exists('description', $attributes) ? is_object($attributes['description']) ? '[html]' . $attributes['description']->evaluate() . '[/html]' : $attributes['description'] : '';
$attach_id = $connection->query_insert('attachments', $attachment, true);
$attachment['id'] = $attach_id;
// Create and document attachment
if (!array_key_exists('type', $attributes)) {
$attributes['type'] = 'auto';
}
$COMCODE_ATTACHMENTS[$pass_id][] = array('tag_type' => $tag, 'type' => 'new', 'attachmenttype' => $attributes['type'], 'description' => $attachment['a_description'], 'id' => intval($attach_id), 'marker' => $marker, 'comcode' => $comcode);
// Marker will allow us to search back and replace this with the added id
} elseif (!is_numeric($id)) {
require_code('uploads');
if (substr($id, 0, 4) == 'new_') {
$_id = substr($id, 4);
if (!is_numeric($_id)) {
$temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:INVALID_ATTACHMENT')));
break;
示例11: simple_add
/**
* Take a file in the gallery uploads directory, and add it to a gallery.
*
* @param URLPATH The URL to the file
* @param URLPATH The thumb URL to the file
* @param string The filename
* @param ID_TEXT The gallery to add to
*/
function simple_add($url, $thumb_url, $file, $cat)
{
require_code('exif');
if (substr($thumb_url, -4, 4) == '.gif') {
$thumb_url = substr($thumb_url, 0, strlen($thumb_url) - 4) . '.png';
}
if (is_video($url)) {
$ret = get_video_details(get_custom_file_base() . '/' . rawurldecode($url), $file, true);
if ($ret !== false) {
list($width, $height, $length) = $ret;
if (is_null($width)) {
$width = 100;
}
if (is_null($height)) {
$height = 100;
}
if (is_null($length)) {
$length = 0;
}
$exif = get_exif_data(get_custom_file_base() . '/' . rawurldecode($url), $file);
$id = add_video($exif['UserComment'], $cat, '', $url, '', 1, post_param_integer('allow_rating', 0), post_param_integer('allow_reviews', post_param_integer('allow_comments', 0)), post_param_integer('allow_trackbacks', 0), post_param('notes', ''), $length, $width, $height);
store_exif('video', strval($id), $exif);
if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries', $cat)) {
syndicate_described_activity('galleries:ACTIVITY_ADD_VIDEO', $exif['UserComment'] == '' ? basename($url) : $exif['UserComment'], '', '', '_SEARCH:galleries:video:' . strval($id), '', '', 'galleries');
}
}
} else {
$ok = true;
if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
require_code('images');
$ok = convert_image(get_custom_base_url() . '/' . $url, get_custom_file_base() . '/' . rawurldecode($thumb_url), -1, -1, intval(get_option('thumb_width')), true);
}
if ($ok) {
$exif = get_exif_data(get_custom_file_base() . '/' . rawurldecode($url), $file);
if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
// See if we need to resize the image
constrain_gallery_image_to_max_size(get_custom_file_base() . '/' . rawurldecode($url), $file, intval(get_option('maximum_image_size')));
// See if we need to do watermarking
$watermark = post_param_integer('watermark', 0);
if ($watermark == 1) {
watermark_gallery_image($cat, rawurldecode($url), $file);
}
}
$id = add_image($exif['UserComment'], $cat, '', $url, $thumb_url, 1, post_param_integer('allow_rating', 0), post_param_integer('allow_reviews', post_param_integer('allow_comments', 0)), post_param_integer('allow_trackbacks', 0), post_param('notes', ''));
store_exif('image', strval($id), $exif);
if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries', $cat)) {
syndicate_described_activity('galleries:ACTIVITY_ADD_IMAGE', $exif['UserComment'] == '' ? basename($url) : $exif['UserComment'], '', '', '_SEARCH:galleries:image:' . strval($id), '', '', 'galleries');
}
}
}
}
示例12: thumb_script
/**
* Allows conversion of a URL to a thumbnail via a simple script.
*/
function thumb_script()
{
$url_full = get_param('url');
if (strpos($url_full, '://') === false) {
$url_full = base64_decode($url_full);
}
require_code('images');
$new_name = url_to_filename($url_full);
if (!is_saveable_image($new_name)) {
$new_name .= '.png';
}
if (is_null($new_name)) {
warn_exit(do_lang_tempcode('URL_THUMB_TOO_LONG'));
}
$file_thumb = get_custom_file_base() . '/uploads/auto_thumbs/' . $new_name;
if (!file_exists($file_thumb)) {
convert_image($url_full, $file_thumb, -1, -1, intval(get_option('thumb_width')), false);
}
$url_thumb = get_custom_base_url() . '/uploads/auto_thumbs/' . rawurlencode($new_name);
if (strpos($url_thumb, chr(10)) !== false || strpos($url_thumb, chr(13)) !== false) {
log_hack_attack_and_exit('HEADER_SPLIT_HACK');
}
header('Location: ' . $url_thumb);
}
示例13: render_field_value
/**
* Convert a field value to something renderable.
*
* @param array The field details
* @param mixed The raw value
* @param integer Position in fieldset
* @param ?array List of fields the output is being limited to (NULL: N/A)
* @return mixed Rendered field (tempcode or string)
*/
function render_field_value($field, $ev, $i, $only_fields)
{
if (is_object($ev)) {
return $ev;
}
if ($ev == '') {
return '';
}
$img_url = $ev;
if (url_is_local($img_url)) {
$img_url = get_custom_base_url() . '/' . $img_url;
}
if (get_option('is_on_gd') == '0' || !function_exists('imagetypes')) {
$img_thumb_url = $img_url;
} else {
$new_name = url_to_filename($ev);
require_code('images');
if (!is_saveable_image($new_name)) {
$new_name .= '.png';
}
$file_thumb = get_custom_file_base() . '/uploads/auto_thumbs/' . $new_name;
if (!file_exists($file_thumb)) {
convert_image($img_url, $file_thumb, -1, -1, intval(get_option('thumb_width')), false);
}
$img_thumb_url = get_custom_base_url() . '/uploads/auto_thumbs/' . rawurlencode($new_name);
}
if (!array_key_exists('c_name', $field)) {
$field['c_name'] = 'other';
}
$tpl_set = $field['c_name'];
$GLOBALS['META_DATA'] += array('image' => $img_url);
return do_template('CATALOGUE_' . $tpl_set . '_ENTRY_FIELD_PICTURE', array('I' => is_null($only_fields) ? '-1' : strval($i), 'CATALOGUE' => $field['c_name'], 'URL' => $img_url, 'THUMB_URL' => $img_thumb_url), NULL, false, 'CATALOGUE_DEFAULT_ENTRY_FIELD_PICTURE');
}
示例14: ocf_member_choose_avatar
/**
* Edit a member's avatar, and check validity.
*
* @param URLPATH The new avatar URL.
* @param ?MEMBER The member (NULL: the current member).
*/
function ocf_member_choose_avatar($avatar_url, $member_id = NULL)
{
if (is_null($member_id)) {
$member_id = get_member();
}
$old = $GLOBALS['FORUM_DB']->query_value('f_members', 'm_avatar_url', array('id' => $member_id));
if ($old == $avatar_url) {
return;
}
// Check it has valid dimensions
if ($avatar_url != '') {
require_code('images');
if (!is_image($avatar_url, true)) {
$ext = get_file_extension($avatar_url);
warn_exit(do_lang_tempcode('UNKNOWN_FORMAT', escape_html($ext)));
}
$stub = url_is_local($avatar_url) ? get_complex_base_url($avatar_url) . '/' : '';
if (get_option('is_on_gd') == '1' && function_exists('imagetypes')) {
$file_path_stub = convert_url_to_path($stub . $avatar_url);
if (!is_null($file_path_stub)) {
$from_file = @file_get_contents($file_path_stub);
} else {
$from_file = http_download_file($stub . $avatar_url, 1024 * 1024 * 4, false);
}
if (is_null($from_file)) {
warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
}
$source = @imagecreatefromstring($from_file);
if ($source === false) {
warn_exit(do_lang_tempcode('CORRUPT_FILE', escape_html($avatar_url)));
}
if (get_file_extension($avatar_url) == 'gif') {
$header = unpack('@6/' . 'vwidth/' . 'vheight', $from_file);
$sx = $header['width'];
$sy = $header['height'];
} else {
$sx = imagesx($source);
$sy = imagesy($source);
}
imagedestroy($source);
$width = ocf_get_member_best_group_property($member_id, 'max_avatar_width');
$height = ocf_get_member_best_group_property($member_id, 'max_avatar_height');
if ($sx > $width || $sy > $height) {
require_code('images');
$file_path = get_custom_file_base() . '/' . rawurldecode($avatar_url);
if (!is_saveable_image($file_path) || !url_is_local($avatar_url)) {
if (url_is_local($avatar_url) && substr($avatar_url, 0, 20) == 'uploads/ocf_avatars/') {
unlink($file_path);
sync_file(rawurldecode($avatar_url));
}
warn_exit(do_lang_tempcode('IMAGE_BAD_DIMENSIONS', strval($width) . 'x' . strval($height), strval($sx) . 'x' . strval($sy)));
}
convert_image($file_path, $file_path, $width, $height, -1, false, get_file_extension($file_path), true, true);
}
}
if (substr($avatar_url, 0, 7) != 'themes/' && addon_installed('ocf_avatars')) {
require_code('notifications');
dispatch_notification('ocf_choose_avatar', NULL, do_lang('CHOOSE_AVATAR_SUBJECT', $GLOBALS['FORUM_DRIVER']->get_username($member_id), NULL, NULL, get_lang($member_id)), do_lang('CHOOSE_AVATAR_BODY', $stub . $avatar_url, $GLOBALS['FORUM_DRIVER']->get_username($member_id), NULL, get_lang($member_id)));
}
}
// Cleanup old avatar
if (url_is_local($old) && (substr($old, 0, 20) == 'uploads/ocf_avatars/' || substr($old, 0, 16) == 'uploads/avatars/') && $old != $avatar_url) {
@unlink(get_custom_file_base() . '/' . rawurldecode($old));
}
$GLOBALS['FORUM_DB']->query_update('f_members', array('m_avatar_url' => $avatar_url), array('id' => $member_id), '', 1);
// Decache from run-time cache
unset($GLOBALS['FORUM_DRIVER']->MEMBER_ROWS_CACHED[$member_id]);
unset($GLOBALS['MEMBER_CACHE_FIELD_MAPPINGS'][$member_id]);
}
示例15: convert_image
// resize image to maximum height and width, if set
if ($tinybrowser['imageresize']['width'] > 0 || $tinybrowser['imageresize']['height'] > 0) {
// assign new width and height values, only if they are less than existing image size
$widthnew = $tinybrowser['imageresize']['width'] > 0 && $tinybrowser['imageresize']['width'] < $imginfo[0] ? $tinybrowser['imageresize']['width'] : $imginfo[0];
$heightnew = $tinybrowser['imageresize']['height'] > 0 && $tinybrowser['imageresize']['height'] < $imginfo[1] ? $tinybrowser['imageresize']['height'] : $imginfo[1];
// only resize if width or height values are different
if ($widthnew != $imginfo[0] || $heightnew != $imginfo[1]) {
$im = convert_image($dest_filename, $mime);
resizeimage($im, $widthnew, $heightnew, $dest_filename, $tinybrowser['imagequality'], $mime);
imagedestroy($im);
}
}
// generate thumbnail
$thumbimg = $folder . '_thumbs/_' . rtrim($file, '_');
if (!file_exists($thumbimg)) {
$im = convert_image($dest_filename, $mime);
resizeimage($im, $tinybrowser['thumbsize'], $tinybrowser['thumbsize'], $thumbimg, $tinybrowser['thumbquality'], $mime);
imagedestroy($im);
}
}
}
}
closedir($handle);
}
$bad = $total - ($good + $dup);
// Check for problem during upload
if ($total > 0 && $bad == $total) {
Header('Location: ./upload.php?type=' . $_GET['type'] . $passfeid . '&permerror=1&total=' . $total);
} else {
Header('Location: ./upload.php?type=' . $_GET['type'] . $passfeid . '&folder=' . $foldernow . '&badfiles=' . $bad . '&goodfiles=' . $good . '&dupfiles=' . $dup);
}