예제 #1
0
     }
     $page['errors'] = array_merge($page['errors'], $errors);
     load_profile_in_template($action, '', $edit_user, 'GUEST_');
     $template->assign('default', array());
     break;
 case 'display':
     foreach ($display_checkboxes as $checkbox) {
         $template->append('display', array($checkbox => $conf[$checkbox]), true);
     }
     $template->append('display', array('picture_informations' => unserialize($conf['picture_informations']), 'NB_CATEGORIES_PAGE' => $conf['nb_categories_page']), true);
     break;
 case 'sizes':
     // we only load the derivatives if it was not already loaded: it occurs
     // when submitting the form and an error remains
     if (!isset($page['sizes_loaded_in_tpl'])) {
         $is_gd = pwg_image::get_library() == 'gd' ? true : false;
         $template->assign('is_gd', $is_gd);
         $template->assign('sizes', array('original_resize_maxwidth' => $conf['original_resize_maxwidth'], 'original_resize_maxheight' => $conf['original_resize_maxheight'], 'original_resize_quality' => $conf['original_resize_quality']));
         foreach ($sizes_checkboxes as $checkbox) {
             $template->append('sizes', array($checkbox => $conf[$checkbox]), true);
         }
         // derivatives = multiple size
         $enabled = ImageStdParams::get_defined_type_map();
         $disabled = @unserialize(@$conf['disabled_derivatives']);
         if ($disabled === false) {
             $disabled = array();
         }
         $tpl_vars = array();
         foreach (ImageStdParams::get_all_types() as $type) {
             $tpl_var = array();
             $tpl_var['must_square'] = $type == IMG_SQUARE ? true : false;
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
// +-----------------------------------------------------------------------+
// | Photo selection                                                       |
// +-----------------------------------------------------------------------+
$upload_max_filesize = min(get_ini_size('upload_max_filesize'), get_ini_size('post_max_size'));
if ($upload_max_filesize == get_ini_size('upload_max_filesize')) {
    $upload_max_filesize_shorthand = get_ini_size('upload_max_filesize', false);
} else {
    $upload_max_filesize_shorthand = get_ini_size('post_max_filesize', false);
}
$template->assign(array('F_ADD_ACTION' => PHOTOS_ADD_BASE_URL, 'upload_max_filesize' => $upload_max_filesize, 'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand, 'chunk_size' => $conf['upload_form_chunk_size']));
// what is the maximum number of pixels permitted by the memory_limit?
if (pwg_image::get_library() == 'gd') {
    $fudge_factor = 1.7;
    $available_memory = get_ini_size('memory_limit') - memory_get_usage();
    $max_upload_width = round(sqrt($available_memory / (2 * $fudge_factor)));
    $max_upload_height = round(2 * $max_upload_width / 3);
    // we don't want dimensions like 2995x1992 but 3000x2000
    $max_upload_width = round($max_upload_width / 100) * 100;
    $max_upload_height = round($max_upload_height / 100) * 100;
    $max_upload_resolution = floor($max_upload_width * $max_upload_height / 1000000);
    // no need to display a limitation warning if the limitation is huge like 20MP
    if ($max_upload_resolution < 25) {
        $template->assign(array('max_upload_width' => $max_upload_width, 'max_upload_height' => $max_upload_height, 'max_upload_resolution' => $max_upload_resolution));
    }
}
//warn the user if the picture will be resized after upload
if ($conf['original_resize']) {
예제 #3
0
파일: intro.php 프로젝트: donseba/Piwigo
SELECT COUNT(*)
  FROM ' . COMMENTS_TABLE . '
;';
    list($nb_comments) = pwg_db_fetch_row(pwg_query($query));
    $template->assign('DB_COMMENTS', l10n_dec('%d comment', '%d comments', $nb_comments));
}
if ($nb_elements > 0) {
    $query = '
SELECT MIN(date_available)
  FROM ' . IMAGES_TABLE . '
;';
    list($first_date) = pwg_db_fetch_row(pwg_query($query));
    $template->assign('first_added', array('DB_DATE' => l10n('first photo added on %s', format_date($first_date))));
}
// graphics library
switch (pwg_image::get_library()) {
    case 'imagick':
        $library = 'ImageMagick';
        $img = new Imagick();
        $version = $img->getVersion();
        if (preg_match('/ImageMagick \\d+\\.\\d+\\.\\d+-?\\d*/', $version['versionString'], $match)) {
            $library = $match[0];
        }
        $template->assign('GRAPHICS_LIBRARY', $library);
        break;
    case 'ext_imagick':
        $library = 'External ImageMagick';
        exec($conf['ext_imagick_dir'] . 'convert -version', $returnarray);
        if (preg_match('/Version: ImageMagick (\\d+\\.\\d+\\.\\d+-?\\d*)/', $returnarray[0], $match)) {
            $library .= ' ' . $match[1];
        }
예제 #4
0
function add_uploaded_file($source_filepath, $original_filename = null, $categories = null, $level = null, $image_id = null, $original_md5sum = null)
{
    // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg
    //
    // 2) keep/resize original
    //
    // 3) register in database
    // TODO
    // * check md5sum (already exists?)
    global $conf, $user;
    if (isset($original_md5sum)) {
        $md5sum = $original_md5sum;
    } else {
        $md5sum = md5_file($source_filepath);
    }
    $file_path = null;
    $is_tiff = false;
    if (isset($image_id)) {
        // this photo already exists, we update it
        $query = '
SELECT
    path
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
        $result = pwg_query($query);
        while ($row = pwg_db_fetch_assoc($result)) {
            $file_path = $row['path'];
        }
        if (!isset($file_path)) {
            die('[' . __FUNCTION__ . '] this photo does not exist in the database');
        }
        // delete all physical files related to the photo (thumbnail, web site, HD)
        delete_element_files(array($image_id));
    } else {
        // this photo is new
        // current date
        list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
        list($year, $month, $day) = preg_split('/[^\\d]/', $dbnow, 4);
        // upload directory hierarchy
        $upload_dir = sprintf(PHPWG_ROOT_PATH . $conf['upload_dir'] . '/%s/%s/%s', $year, $month, $day);
        // compute file path
        $date_string = preg_replace('/[^\\d]/', '', $dbnow);
        $random_string = substr($md5sum, 0, 8);
        $filename_wo_ext = $date_string . '-' . $random_string;
        $file_path = $upload_dir . '/' . $filename_wo_ext . '.';
        list($width, $height, $type) = getimagesize($source_filepath);
        if (IMAGETYPE_PNG == $type) {
            $file_path .= 'png';
        } elseif (IMAGETYPE_GIF == $type) {
            $file_path .= 'gif';
        } elseif (IMAGETYPE_TIFF_MM == $type or IMAGETYPE_TIFF_II == $type) {
            $is_tiff = true;
            $file_path .= 'tif';
        } elseif (IMAGETYPE_JPEG == $type) {
            $file_path .= 'jpg';
        } elseif (isset($conf['upload_form_all_types']) and $conf['upload_form_all_types']) {
            $original_extension = strtolower(get_extension($original_filename));
            if (in_array($original_extension, $conf['file_ext'])) {
                $file_path .= $original_extension;
            } else {
                die('unexpected file type');
            }
        } else {
            die('forbidden file type');
        }
        prepare_directory($upload_dir);
    }
    if (is_uploaded_file($source_filepath)) {
        move_uploaded_file($source_filepath, $file_path);
    } else {
        rename($source_filepath, $file_path);
    }
    @chmod($file_path, 0644);
    if ($is_tiff and pwg_image::get_library() == 'ext_imagick') {
        // move the uploaded file to pwg_representative sub-directory
        $representative_file_path = dirname($file_path) . '/pwg_representative/';
        $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
        $representative_ext = $conf['tiff_representative_ext'];
        $representative_file_path .= $representative_ext;
        prepare_directory(dirname($representative_file_path));
        $exec = $conf['ext_imagick_dir'] . 'convert';
        if ('jpg' == $conf['tiff_representative_ext']) {
            $exec .= ' -quality 98';
        }
        $exec .= ' "' . realpath($file_path) . '"';
        $dest = pathinfo($representative_file_path);
        $exec .= ' "' . realpath($dest['dirname']) . '/' . $dest['basename'] . '"';
        $exec .= ' 2>&1';
        @exec($exec, $returnarray);
        // sometimes ImageMagick creates file-0.jpg (full size) + file-1.jpg
        // (thumbnail). I don't know how to avoid it.
        $representative_file_abspath = realpath($dest['dirname']) . '/' . $dest['basename'];
        if (!file_exists($representative_file_abspath)) {
            $first_file_abspath = preg_replace('/\\.' . $representative_ext . '$/', '-0.' . $representative_ext, $representative_file_abspath);
            if (file_exists($first_file_abspath)) {
                rename($first_file_abspath, $representative_file_abspath);
            }
        }
    }
    //
    // generate pwg_representative in case of video
    //
    $ffmpeg_video_exts = array('wmv', 'mov', 'mkv', 'mp4', 'mpg', 'flv', 'asf', 'xvid', 'divx', 'mpeg', 'avi', 'rm');
    if (isset($original_extension) and in_array($original_extension, $ffmpeg_video_exts)) {
        $representative_file_path = dirname($file_path) . '/pwg_representative/';
        $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
        $representative_ext = 'jpg';
        $representative_file_path .= $representative_ext;
        prepare_directory(dirname($representative_file_path));
        $second = 1;
        $ffmpeg = $conf['ffmpeg_dir'] . 'ffmpeg';
        $ffmpeg .= ' -i "' . $file_path . '"';
        $ffmpeg .= ' -an -ss ' . $second;
        $ffmpeg .= ' -t 1 -r 1 -y -vcodec mjpeg -f mjpeg';
        $ffmpeg .= ' "' . $representative_file_path . '"';
        // file_put_contents('/tmp/ffmpeg.log', "\n==== ".date('c')."\n".__FUNCTION__.' : '.$ffmpeg."\n", FILE_APPEND);
        @exec($ffmpeg);
        if (!file_exists($representative_file_path)) {
            $representative_ext = null;
        }
    }
    if (isset($original_extension) and 'pdf' == $original_extension and pwg_image::get_library() == 'ext_imagick') {
        $representative_file_path = dirname($file_path) . '/pwg_representative/';
        $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
        $representative_ext = 'jpg';
        $representative_file_path .= $representative_ext;
        prepare_directory(dirname($representative_file_path));
        $exec = $conf['ext_imagick_dir'] . 'convert';
        $exec .= ' -quality 98';
        $exec .= ' "' . realpath($file_path) . '"[0]';
        $dest = pathinfo($representative_file_path);
        $exec .= ' "' . realpath($dest['dirname']) . '/' . $dest['basename'] . '"';
        $exec .= ' 2>&1';
        @exec($exec, $returnarray);
    }
    if (pwg_image::get_library() != 'gd') {
        if ($conf['original_resize']) {
            $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']);
            if ($need_resize) {
                $img = new pwg_image($file_path);
                $img->pwg_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight'], $conf['original_resize_quality'], $conf['upload_form_automatic_rotation'], false);
                $img->destroy();
            }
        }
    }
    // we need to save the rotation angle in the database to compute
    // width/height of "multisizes"
    $rotation_angle = pwg_image::get_rotation_angle($file_path);
    $rotation = pwg_image::get_rotation_code_from_angle($rotation_angle);
    $file_infos = pwg_image_infos($file_path);
    if (isset($image_id)) {
        $update = array('file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation);
        if (isset($level)) {
            $update['level'] = $level;
        }
        single_update(IMAGES_TABLE, $update, array('id' => $image_id));
    } else {
        // database registration
        $file = pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path));
        $insert = array('file' => $file, 'name' => get_name_from_file($file), 'date_available' => $dbnow, 'path' => preg_replace('#^' . preg_quote(PHPWG_ROOT_PATH) . '#', '', $file_path), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation);
        if (isset($level)) {
            $insert['level'] = $level;
        }
        if (isset($representative_ext)) {
            $insert['representative_ext'] = $representative_ext;
        }
        single_insert(IMAGES_TABLE, $insert);
        $image_id = pwg_db_insert_id(IMAGES_TABLE);
    }
    if (isset($categories) and count($categories) > 0) {
        associate_images_to_categories(array($image_id), $categories);
    }
    // update metadata from the uploaded file (exif/iptc)
    if ($conf['use_exif'] and !function_exists('read_exif_data')) {
        $conf['use_exif'] = false;
    }
    sync_metadata(array($image_id));
    invalidate_user_cache();
    // cache thumbnail
    $query = '
SELECT
    id,
    path
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
    $image_infos = pwg_db_fetch_assoc(pwg_query($query));
    set_make_full_url();
    // in case we are on uploadify.php, we have to replace the false path
    $thumb_url = preg_replace('#admin/include/i#', 'i', DerivativeImage::thumb_url($image_infos));
    unset_make_full_url();
    fetchRemote($thumb_url, $dest);
    return $image_id;
}
예제 #5
0
    /* Update the database - No action done on the video */
    $rotation_code = pwg_image::get_rotation_code_from_angle($_POST['angle']);
    $query = "UPDATE " . IMAGES_TABLE . " SET rotation='" . $rotation_code . "', `date_metadata_update`=CURDATE() WHERE `id`=" . $_GET['image_id'] . ";";
    pwg_query($query);
    /* Retrieve direct information about picture */
    $query = "SELECT id,path,representative_ext FROM " . IMAGES_TABLE . " WHERE " . SQL_VIDEOS . " AND id = " . $_GET['image_id'] . ";";
    $row = pwg_db_fetch_assoc(pwg_query($query));
    /* Delete previous derivatives */
    delete_element_derivatives($row);
    array_push($page['infos'], l10n('The photo was updated'));
}
// +-----------------------------------------------------------------------+
// | Tabs                                                                  |
// +-----------------------------------------------------------------------+
$tabsheet = new tabsheet();
$tabsheet->set_id('photo');
$tabsheet->select('rotate');
$tabsheet->assign();
// +-----------------------------------------------------------------------+
// |                             template init                             |
// +-----------------------------------------------------------------------+
$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin_rotate.tpl'));
// Retrieve direct information about picture
$query = "SELECT * FROM " . IMAGES_TABLE . " WHERE " . SQL_VIDEOS . " AND id = " . $_GET['image_id'] . ";";
$row = pwg_db_fetch_assoc(pwg_query($query));
$angles = array(array('value' => 270, 'name' => l10n('90° right')), array('value' => 90, 'name' => l10n('90° left')), array('value' => 180, 'name' => l10n('180°')));
$template->assign(array('F_ACTION' => $self_url, 'TN_SRC' => DerivativeImage::thumb_url($row), 'TITLE' => render_element_name($row), 'angles' => $angles, 'angle_selected' => pwg_image::get_rotation_angle_from_code($row['rotation']), 'library' => pwg_image::get_library(), 'PWG_TOKEN' => get_pwg_token()));
// +-----------------------------------------------------------------------+
// | sending html code                                                     |
// +-----------------------------------------------------------------------+
$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
예제 #6
0
function upload_file_tiff($representative_ext, $file_path)
{
    global $logger, $conf;
    $logger->info(__FUNCTION__ . ', $file_path = ' . $file_path . ', $representative_ext = ' . $representative_ext);
    if (isset($representative_ext)) {
        return $representative_ext;
    }
    if (pwg_image::get_library() != 'ext_imagick') {
        return $representative_ext;
    }
    if (!in_array(strtolower(get_extension($file_path)), array('tif', 'tiff'))) {
        return $representative_ext;
    }
    // move the uploaded file to pwg_representative sub-directory
    $representative_file_path = dirname($file_path) . '/pwg_representative/';
    $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
    $representative_ext = $conf['tiff_representative_ext'];
    $representative_file_path .= $representative_ext;
    prepare_directory(dirname($representative_file_path));
    $exec = $conf['ext_imagick_dir'] . 'convert';
    if ('jpg' == $conf['tiff_representative_ext']) {
        $exec .= ' -quality 98';
    }
    $exec .= ' "' . realpath($file_path) . '"';
    $dest = pathinfo($representative_file_path);
    $exec .= ' "' . realpath($dest['dirname']) . '/' . $dest['basename'] . '"';
    $exec .= ' 2>&1';
    @exec($exec, $returnarray);
    // sometimes ImageMagick creates file-0.jpg (full size) + file-1.jpg
    // (thumbnail). I don't know how to avoid it.
    $representative_file_abspath = realpath($dest['dirname']) . '/' . $dest['basename'];
    if (!file_exists($representative_file_abspath)) {
        $first_file_abspath = preg_replace('/\\.' . $representative_ext . '$/', '-0.' . $representative_ext, $representative_file_abspath);
        if (file_exists($first_file_abspath)) {
            rename($first_file_abspath, $representative_file_abspath);
        }
    }
    return get_extension($representative_file_abspath);
}