Example #1
0
File: i.php Project: donseba/Piwigo
    $page['rotation_angle'] = 0;
}
pwg_db_close();
if (!try_switch_source($params, $src_mtime) && $params->type == IMG_CUSTOM) {
    $sharpen = 0;
    foreach (ImageStdParams::get_defined_type_map() as $std_params) {
        $sharpen += $std_params->sharpen;
    }
    $params->sharpen = round($sharpen / count(ImageStdParams::get_defined_type_map()));
}
if (!mkgetdir(dirname($page['derivative_path']))) {
    ierror("dir create error", 500);
}
ignore_user_abort(true);
@set_time_limit(0);
$image = new pwg_image($page['src_path']);
$timing['load'] = time_step($step);
$changes = 0;
// rotate
if (0 != $page['rotation_angle']) {
    $image->rotate($page['rotation_angle']);
    $changes++;
    $timing['rotate'] = time_step($step);
}
// Crop & scale
$o_size = $d_size = array($image->get_width(), $image->get_height());
$params->sizing->compute($o_size, $page['coi'], $crop_rect, $scaled_size);
if ($crop_rect) {
    $changes++;
    $image->crop($crop_rect->width(), $crop_rect->height(), $crop_rect->l, $crop_rect->t);
    $timing['crop'] = time_step($step);
Example #2
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']) {
Example #4
0
function vjs_render_media($content, $picture)
{
    global $template, $picture, $page, $conf, $user, $refresh;
    //print_r( $picture['current']);
    // do nothing if the current picture is actually an image !
    if (array_key_exists('src_image', @$picture['current']) && @$picture['current']['src_image']->is_original()) {
        return $content;
    }
    // In case it is not an image but not a supported video file by the plugin
    if (vjs_valid_extension(get_extension($picture['current']['path'])) === false) {
        return $content;
    }
    // In case, we handle a large video, we define a MAX_HEIGHT
    // variable to limit the display size.
    $MAX_HEIGHT = isset($conf['vjs_conf']['max_height']) ? $conf['vjs_conf']['max_height'] : '480';
    if (isset($user['maxheight']) and $user['maxheight'] != '') {
        $MAX_HEIGHT = $user['maxwidth'];
    }
    //print "MAX_HEIGHT=" . $MAX_HEIGHT;
    //print_r($user);
    $extension = vjs_get_mimetype_from_ext(get_extension($picture['current']['path']));
    //print "extension\n";
    //print_r($extension);
    // Video file -- Guess resolution base on height
    if (isset($picture['current']['width'])) {
        $width = $picture['current']['width'];
    }
    if (isset($picture['current']['height'])) {
        $height = $picture['current']['height'];
    }
    if (!isset($width) || !isset($height) || $width == 0 || $height == 0) {
        // If guess was unsuccessful, fallback to default 16/9 resolution 720x480
        // Mostly happend when video metadata was incorrectly sync into PWG
        // This is the case for ogv video for example.
        $height = 480;
        $width = round(16 * 480 / 9, 0);
    }
    //print "Video height=" . $height . " width=". $width;
    // Resize if video is too height
    //print $height .">". $MAX_HEIGHT;
    if ($height > $MAX_HEIGHT) {
        $height = $MAX_HEIGHT;
        $width = round(16 * $MAX_HEIGHT / 9, 0);
        //print "MAX_HEIGHT height=" . $height . " width=". $width;
    }
    // Upscale if video is too small
    $upscale = isset($conf['vjs_conf']['upscale']) ? strbool($conf['vjs_conf']['upscale']) : false;
    if ($upscale and $height < $MAX_HEIGHT) {
        $height = $MAX_HEIGHT;
        $width = round(16 * $MAX_HEIGHT / 9, 0);
        //print "UPSCALE height=" . $height . " width=". $width;
    }
    // Load parameter, fallback to default if unset
    $skin = isset($conf['vjs_conf']['skin']) ? $conf['vjs_conf']['skin'] : 'vjs-default-skin';
    $customcss = isset($conf['vjs_customcss']) ? $conf['vjs_customcss'] : '';
    $preload = isset($conf['vjs_conf']['preload']) ? $conf['vjs_conf']['preload'] : 'none';
    $loop = isset($conf['vjs_conf']['loop']) ? strbool($conf['vjs_conf']['loop']) : false;
    $controls = isset($conf['vjs_conf']['controls']) ? strbool($conf['vjs_conf']['controls']) : false;
    $volume = isset($conf['vjs_conf']['volume']) ? $conf['vjs_conf']['volume'] : '1';
    $language = isset($conf['vjs_conf']['language']) ? $conf['vjs_conf']['language'] : 'en';
    // Slideshow : The video needs to be launch automatically in
    // slideshow mode. The refresh of the page is set to the
    // duration of the video.
    $autoplay = isset($conf['vjs_conf']['autoplay']) ? strbool($conf['vjs_conf']['autoplay']) : false;
    if ($page['slideshow']) {
        $refresh = 20;
        // TODO move to separate DB to actualy get this details information
        $autoplay = true;
        $loop = false;
    }
    // Assing the CSS file according to the skin
    $available_skins = array('vjs-default-skin' => 'video-js.min.css', 'vjs-bluebox-skin' => 'bluebox-skin.css', 'vjs-redtube-skin' => 'redtube-skin.css');
    $skincss = $available_skins[$skin];
    // Guess the poster extension
    $file_wo_ext = pathinfo($picture['current']['path']);
    $file_dir = dirname($picture['current']['path']);
    $poster = embellish_url($picture['current']['src_image']->get_path());
    //print $poster;
    // Try to find multiple video source
    $vjs_extensions = array('ogg', 'ogv', 'mp4', 'm4v', 'webm', 'webmv');
    $files_ext = array_merge(array(), $vjs_extensions, array_map('strtoupper', $vjs_extensions));
    // Add the current file in array
    $videos[] = array('src' => embellish_url($picture['current']['element_url']), 'ext' => $extension);
    // Add any other video source format
    foreach ($files_ext as $file_ext) {
        $file = $file_dir . "/pwg_representative/" . $file_wo_ext['filename'] . "." . $file_ext;
        if (file_exists($file)) {
            array_push($videos, array('src' => embellish_url(get_gallery_home_url() . $file_dir . "/pwg_representative/" . $file_wo_ext['filename'] . "." . $file_ext), 'ext' => vjs_get_mimetype_from_ext($file_ext)));
        }
    }
    //print_r($videos);
    // Sort array to have MP4 first in the source list for iOS support
    foreach ($videos as $key => $row) {
        $src[$key] = $row['src'];
        $ext[$key] = $row['ext'];
    }
    array_multisort($src, SORT_ASC, $ext, SORT_ASC, $videos);
    //print_r($videos);
    /* Try to find WebVTT */
    $file = $file_dir . "/pwg_representative/" . $file_wo_ext['filename'] . ".vtt";
    $subtitles = null;
    if (file_exists($file)) {
        $subtitles = '<track kind="subtitles" src="' . embellish_url(get_gallery_home_url() . $file) . '" srclang="' . $language . '" label="English"></track>';
    }
    /* Thumbnail videojs plugin */
    $thumbnails_plugin = isset($conf['vjs_conf']['plugins']['thumbnails']) ? strbool($conf['vjs_conf']['plugins']['thumbnails']) : false;
    $thumbnails = array();
    if ($thumbnails_plugin) {
        $filematch = $file_dir . "/pwg_representative/" . $file_wo_ext['filename'] . "-th_*";
        $matches = glob($filematch);
        if (is_array($matches) and !empty($matches)) {
            $sort = array();
            // A list of sort columns and their data to pass to array_multisort
            foreach ($matches as $filename) {
                $ext = explode("-th_", $filename);
                $second = explode(".", $ext[1]);
                include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
                include_once PHPWG_ROOT_PATH . 'admin/include/image.class.php';
                $rotate = pwg_image::get_rotation_angle_from_code($picture['current']['rotation']);
                // ./galleries/videos/pwg_representative/trailer_480p-th_0.jpg
                //echo "$filename second " . $second[0]. "\n";
                $thumbnails[] = array('second' => $second[0], 'source' => embellish_url(get_gallery_home_url() . $filename), 'rotate' => $rotate);
                $sort['second'][$second[0]] = $second[0];
            }
            // Sort thumbnails by second ASC
            !empty($sort['second']) and array_multisort($sort['second'], SORT_ASC, $thumbnails);
        }
        //$thumbnails = array( array('second' => 0, 'source' => $poster), array('second' => 5, 'source' => $poster));
        //print_r($thumbnails);
    }
    /* ZoomRotate videojs plugin */
    $zoomrotate_plugin = isset($conf['vjs_conf']['plugins']['zoomrotate']) ? strbool($conf['vjs_conf']['plugins']['zoomrotate']) : false;
    $zoomrotate = array();
    if ($zoomrotate_plugin) {
        // TODO Disable if playing on iOS, as it read the metadata itself
        if ($picture['current']['rotation'] != null) {
            include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
            include_once PHPWG_ROOT_PATH . 'admin/include/image.class.php';
            // rotation is $picture['current']['rotation']
            // zoom is witdh / height
            $rotate = pwg_image::get_rotation_angle_from_code($picture['current']['rotation']);
            $zoomrotate = array('rotate' => $rotate, 'zoom' => round($width / $height, 1, PHP_ROUND_HALF_DOWN));
            // Change the video player size
            $tmp_width = $width;
            $tmp_height = $height;
            $width = $tmp_height;
            $height = $tmp_width;
        }
    }
    /* Watermark videojs plugin */
    $watermark_plugin = isset($conf['vjs_conf']['plugins']['watermark']) ? strbool($conf['vjs_conf']['plugins']['watermark']) : false;
    $watermark = array();
    if ($watermark_plugin) {
        $derivatives = unserialize($conf['derivatives']);
        if (is_array($derivatives) and !empty($derivatives) and $derivatives['w']->file != null) {
            $watermark = array('file' => embellish_url(get_gallery_home_url() . $derivatives['w']->file), 'xpos' => $derivatives['w']->xpos, 'ypos' => $derivatives['w']->ypos, 'xrepeat' => $derivatives['w']->xrepeat, 'opacity' => $derivatives['w']->opacity);
        }
    }
    // Generate HTML5 tags
    // Why the data-setup attribute does not work if only one video
    $options = "";
    if ($controls) {
        $options .= "controls";
    }
    if ($autoplay) {
        $options .= " autoplay ";
    }
    if ($loop) {
        $options .= " loop ";
    }
    $options .= ' preload="' . $preload . '"';
    // Select the template
    $template->set_filenames(array('vjs_content' => dirname(__FILE__) . "/template/vjs-player.tpl"));
    // Ensure the ratio is always below 100%, there is for sure a better way!
    $ratio = round($height / $width * 100, 2);
    if ($ratio >= 100) {
        $ratio = round($width / $height * 100, 2);
    }
    // Assign the template variables
    // We use here the piwigo's get_gallery_home_url function to build
    // the full URL as suggested by videojs for flash fallback compatibility
    $template->assign(array('VIDEOJS_POSTER_URL' => embellish_url(get_gallery_home_url() . $poster), 'VIDEOJS_PATH' => embellish_url(get_gallery_home_url() . VIDEOJS_PATH), 'WIDTH' => $width, 'RATIO' => $ratio, 'OPTIONS' => $options, 'VIDEOJS_SKIN' => $skin, 'VIDEOJS_SKINCSS' => $skincss, 'VIDEOJS_CUSTOMCSS' => $customcss, 'volume' => $volume, 'subtitles' => $subtitles, 'thumbnails' => $thumbnails, 'zoomrotate' => $zoomrotate, 'watermark' => $watermark, 'videos' => $videos));
    // Return the rendered html
    $vjs_content = $template->parse('vjs_content', true);
    return $vjs_content;
}
Example #5
0
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];
        }
 function sharpen($amount)
 {
     $m = pwg_image::get_sharpen_matrix($amount);
     return imageconvolution($this->image, $m, 1, 0);
 }
Example #7
0
    }
    // Import metadata into the DB
    if (isset($_GET['sync_metadata']) and $_GET['sync_metadata'] == 1 and !empty($exif) and count($exif) > 0) {
        array_push($page['infos'], ' metadata: ' . count($exif) . " " . vjs_pprint_r($exif));
        $dbfields = explode(",", "filesize,width,height,latitude,longitude,date_creation,rotation");
        $query = "UPDATE " . IMAGES_TABLE . " SET " . vjs_dbSet($dbfields, $exif) . ", `date_metadata_update`=CURDATE() WHERE `id`=" . $_GET['image_id'] . ";";
        pwg_query($query);
    }
    // replace some value by human readable string
    $exif['name'] = (string) $general->CompleteName;
    $exif['filename'] = (string) $general->FileName;
    $exif['filesize'] = (string) $general->FileSize_String;
    $exif['duration'] = (string) $general->Duration_String;
    $exif['bitrate'] = (string) $video->BitRate_String;
    $exif['sampling_rate'] = (string) $audio->SamplingRate_String;
    isset($exif['rotation']) and $exif['rotation'] = pwg_image::get_rotation_angle_from_code($exif['rotation']) . "°";
    ksort($exif);
}
// Try to guess the poster extension
$parts = pathinfo($picture['path']);
$poster = vjs_get_poster_file(array((string) $general->FolderName . "/pwg_representative/" . $parts['filename'] . ".jpg" => get_gallery_home_url() . $parts['dirname'] . "/pwg_representative/" . $parts['filename'] . ".jpg", (string) $general->FolderName . "/pwg_representative/" . $parts['filename'] . ".png" => get_gallery_home_url() . $parts['dirname'] . "/pwg_representative/" . $parts['filename'] . ".png"));
// If none found, it create an strpos error
if (strlen($poster) > 0) {
    $poster = embellish_url($poster);
}
//print $poster;
// Try to find multiple video source
$extension = $parts['extension'];
$vjs_extensions = array('ogg', 'ogv', 'mp4', 'm4v', 'webm', 'webmv');
$files_ext = array_merge(array(), $vjs_extensions, array_map('strtoupper', $vjs_extensions));
// Add the current file in array
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;
}
Example #9
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');
Example #10
0
if (isset($video->BitRate)) {
    $exif['bitrate'] = (string) $video->BitRate;
}
if (isset($video->Width)) {
    $exif['width'] = (string) $video->Width;
}
if (isset($video->Height)) {
    $exif['height'] = (string) $video->Height;
}
if (isset($video->DisplayAspectRatio)) {
    $exif['display_aspect_ratio'] = (string) $video->DisplayAspectRatio;
}
if (isset($video->Rotation) and (int) $video->Rotation != 0) {
    include_once PHPWG_ROOT_PATH . 'admin/include/image.class.php';
    //print (int)$video->Rotation[0];
    $rotation_code = pwg_image::get_rotation_code_from_angle((int) $video->Rotation);
    $exif['rotation'] = $rotation_code;
}
if (isset($video->FrameRate)) {
    $exif['frame_rate'] = (string) $video->FrameRate;
}
/*
print $video->Bit_rate[0]."<br/>\n";
print $video->Width[0]."<br/>\n";
print $video->Height[0]."<br/>\n";
print $video->Display_aspect_ratio[0]."<br/>\n";
print $video->Rotation[0]."<br/>\n";
print $video->Frame_rate[0]."<br/>\n";
*/
/*
 *Audio
Example #11
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);
}