当前位置: 首页>>代码示例>>PHP>>正文


PHP run_command函数代码示例

本文整理汇总了PHP中run_command函数的典型用法代码示例。如果您正苦于以下问题:PHP run_command函数的具体用法?PHP run_command怎么用?PHP run_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了run_command函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_original_imagesize

function get_original_imagesize($ref = "", $path = "", $extension = "jpg")
{
    $fileinfo = array();
    if ($ref == "" || $path == "") {
        return false;
    }
    global $imagemagick_path, $imagemagick_calculate_sizes;
    $file = $path;
    $filesize = filesize_unlimited($file);
    # imagemagick_calculate_sizes is normally turned off
    if (isset($imagemagick_path) && $imagemagick_calculate_sizes) {
        # Use ImageMagick to calculate the size
        $prefix = '';
        # Camera RAW images need prefix
        if (preg_match('/^(dng|nef|x3f|cr2|crw|mrw|orf|raf|dcr)$/i', $extension, $rawext)) {
            $prefix = $rawext[0] . ':';
        }
        # Locate imagemagick.
        $identify_fullpath = get_utility_path("im-identify");
        if ($identify_fullpath == false) {
            exit("Could not find ImageMagick 'identify' utility at location '{$imagemagick_path}'.");
        }
        # Get image's dimensions.
        $identcommand = $identify_fullpath . ' -format %wx%h ' . escapeshellarg($prefix . $file) . '[0]';
        $identoutput = run_command($identcommand);
        preg_match('/^([0-9]+)x([0-9]+)$/ims', $identoutput, $smatches);
        @(list(, $sw, $sh) = $smatches);
        if ($sw != '' && $sh != '') {
            sql_query("insert into resource_dimensions (resource, width, height, file_size) values('" . $ref . "', '" . $sw . "', '" . $sh . "', '" . $filesize . "')");
        }
    } else {
        # check if this is a raw file.
        $rawfile = false;
        if (preg_match('/^(dng|nef|x3f|cr2|crw|mrw|orf|raf|dcr)$/i', $extension, $rawext)) {
            $rawfile = true;
        }
        # Use GD to calculate the size
        if (!(@(list($sw, $sh) = @getimagesize($file)) === false) && !$rawfile) {
            sql_query("insert into resource_dimensions (resource, width, height, file_size) values('" . $ref . "', '" . $sw . "', '" . $sh . "', '" . $filesize . "')");
        } else {
            # Assume size cannot be calculated.
            $sw = "?";
            $sh = "?";
            global $ffmpeg_supported_extensions;
            if (in_array(strtolower($extension), $ffmpeg_supported_extensions) && function_exists('json_decode')) {
                $ffprobe_fullpath = get_utility_path("ffprobe");
                $file = get_resource_path($ref, true, "", false, $extension);
                $ffprobe_output = run_command($ffprobe_fullpath . " -v 0 " . escapeshellarg($file) . " -show_streams -of json");
                $ffprobe_array = json_decode($ffprobe_output, true);
                # Different versions of ffprobe store the dimensions in different parts of the json output. Test both.
                if (!empty($ffprobe_array['width'])) {
                    $sw = intval($ffprobe_array['width']);
                }
                if (!empty($ffprobe_array['height'])) {
                    $sh = intval($ffprobe_array['height']);
                }
                if (isset($ffprobe_array['streams']) && is_array($ffprobe_array['streams'])) {
                    foreach ($ffprobe_array['streams'] as $stream) {
                        if (!empty($stream['codec_type']) && $stream['codec_type'] === 'video') {
                            $sw = intval($stream['width']);
                            $sh = intval($stream['height']);
                            break;
                        }
                    }
                }
            }
            if ($sw !== '?' && $sh !== '?') {
                # Size could be calculated after all
                sql_query("insert into resource_dimensions (resource, width, height, file_size) values('" . $ref . "', '" . $sw . "', '" . $sh . "', '" . $filesize . "')");
            } else {
                # Size cannot be calculated.
                $sw = "?";
                $sh = "?";
                # Insert a dummy row to prevent recalculation on every view.
                sql_query("insert into resource_dimensions (resource, width, height, file_size) values('" . $ref . "','0', '0', '" . $filesize . "')");
            }
        }
    }
    $fileinfo[0] = $filesize;
    $fileinfo[1] = $sw;
    $fileinfo[2] = $sh;
    return $fileinfo;
}
开发者ID:perryrothjohnson,项目名称:resourcespace,代码行数:83,代码来源:resource_functions.php

示例2: get_utility_version

function get_utility_version($utilityname)
{
    global $lang;
    # Get utility path.
    $utility_fullpath = get_utility_path($utilityname, $path);
    # Get utility display name.
    $name = get_utility_displayname($utilityname);
    # Check path.
    if ($path == null) {
        # There was no complete path to check - the utility is not installed.
        $error_msg = $lang["status-notinstalled"];
        return array("name" => $name, "version" => "", "success" => false, "error" => $error_msg);
    }
    if ($utility_fullpath == false) {
        # There was a path but it was incorrect - the utility couldn't be found.
        $error_msg = $lang["status-fail"] . ":<br>" . str_replace("?", $path, $lang["softwarenotfound"]);
        return array("name" => $name, "version" => "", "success" => false, "error" => $error_msg);
    }
    # Look up the argument to use to get the version.
    switch (strtolower($utilityname)) {
        case "exiftool":
            $version_argument = "-ver";
            break;
        default:
            $version_argument = "-version";
    }
    # Check execution and find out version.
    $version_command = $utility_fullpath . " " . $version_argument;
    $version = run_command($version_command);
    switch (strtolower($utilityname)) {
        case "im-convert":
            if (strpos($version, "ImageMagick") !== false) {
                $name = "ImageMagick";
            }
            if (strpos($version, "GraphicsMagick") !== false) {
                $name = "GraphicsMagick";
            }
            if ($name == "ImageMagick" || $name == "GraphicsMagick") {
                $expected = true;
            } else {
                $expected = false;
            }
            break;
        case "ghostscript":
            if (strpos(strtolower($version), "ghostscript") === false) {
                $expected = false;
            } else {
                $expected = true;
            }
            break;
        case "ffmpeg":
            if (strpos(strtolower($version), "ffmpeg") === false) {
                $expected = false;
            } else {
                $expected = true;
            }
            break;
        case "exiftool":
            if (preg_match("/^([0-9]+)+\\.([0-9]+)\$/", $version) == false) {
                $expected = false;
            } else {
                $expected = true;
            }
            break;
    }
    if ($expected == false) {
        # There was a correct path but the version check failed - unexpected output when executing the command.
        $error_msg = $lang["status-fail"] . ":<br>" . str_replace(array("%command", "%output"), array($version_command, $version), $lang["execution_failed"]);
        return array("name" => $name, "version" => "", "success" => false, "error" => $error_msg);
    } else {
        # There was a working path and the output was the expected - the version is returned.
        $s = explode("\n", $version);
        return array("name" => $name, "version" => $s[0], "success" => true, "error" => "");
    }
}
开发者ID:chandradrupal,项目名称:resourcespace,代码行数:75,代码来源:check.php

示例3: generate_transform_preview

function generate_transform_preview($ref){
	global $storagedir;	
        global $imagemagick_path;
	global $imversion;

	if (!isset($imversion)){
		$imversion = get_imagemagick_version();
	}

	$tmpdir = get_temp_dir();

        // get imagemagick path
        $command = get_utility_path("im-convert");
        if ($command==false) {exit("Could not find ImageMagick 'convert' utility.");}

        $orig_ext = sql_value("select file_extension value from resource where ref = '$ref'",'');
        $originalpath= get_resource_path($ref,true,'',false,$orig_ext);

	# Since this check is in get_temp_dir() omit: if(!is_dir($storagedir."/tmp")){mkdir($storagedir."/tmp",0777);}
	if(!is_dir(get_temp_dir() . "/transform_plugin")){mkdir(get_temp_dir() . "/transform_plugin",0777);}

       if ($imversion[0]<6 || ($imversion[0] == 6 &&  $imversion[1]<7) || ($imversion[0] == 6 && $imversion[1] == 7 && $imversion[2]<5)){
                $colorspace1 = " -colorspace sRGB ";
                $colorspace2 =  " -colorspace RGB ";
        } else {
                $colorspace1 = " -colorspace RGB ";
                $colorspace2 =  " -colorspace sRGB ";
        }

        $command .= " \"$originalpath\" +matte -delete 1--1 -flatten $colorspace1 -geometry 450 $colorspace2 \"$tmpdir/transform_plugin/pre_$ref.jpg\"";
        run_command($command);


	// while we're here, clean up any old files still hanging around
	$dp = opendir(get_temp_dir() . "/transform_plugin");
	while ($file = readdir($dp)) {
		if ($file <> '.' && $file <> '..'){
			if ((filemtime(get_temp_dir() . "/transform_plugin/$file")) < (strtotime('-2 days'))) {
				unlink(get_temp_dir() . "/transform_plugin/$file");
			}
		}
	}
	closedir($dp);

        return true;
  
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:47,代码来源:transform_functions.php

示例4: generate_transform_preview

function generate_transform_preview($ref)
{
    global $storagedir;
    global $imagemagick_path;
    global $imversion;
    if (!isset($imversion)) {
        $imversion = get_imagemagick_version();
    }
    $tmpdir = get_temp_dir();
    // get imagemagick path
    $command = get_utility_path("im-convert");
    if ($command == false) {
        exit("Could not find ImageMagick 'convert' utility.");
    }
    $orig_ext = sql_value("select file_extension value from resource where ref = '{$ref}'", '');
    $transformsourcepath = get_resource_path($ref, true, 'scr', false, 'jpg');
    //use screen size if available to save time
    if (!file_exists($transformsourcepath)) {
        $transformsourcepath = get_resource_path($ref, true, '', false, $orig_ext);
    }
    # Since this check is in get_temp_dir() omit: if(!is_dir($storagedir."/tmp")){mkdir($storagedir."/tmp",0777);}
    if (!is_dir(get_temp_dir() . "/transform_plugin")) {
        mkdir(get_temp_dir() . "/transform_plugin", 0777);
    }
    if ($imversion[0] < 6 || $imversion[0] == 6 && $imversion[1] < 7 || $imversion[0] == 6 && $imversion[1] == 7 && $imversion[2] < 5) {
        $colorspace1 = " -colorspace sRGB ";
        $colorspace2 = " -colorspace RGB ";
    } else {
        $colorspace1 = " -colorspace RGB ";
        $colorspace2 = " -colorspace sRGB ";
    }
    $command .= " \"{$transformsourcepath}\"[0] +matte -flatten {$colorspace1} -geometry 450 {$colorspace2} \"{$tmpdir}/transform_plugin/pre_{$ref}.jpg\"";
    run_command($command);
    // while we're here, clean up any old files still hanging around
    $dp = opendir(get_temp_dir() . "/transform_plugin");
    while ($file = readdir($dp)) {
        if ($file != '.' && $file != '..') {
            if (filemtime(get_temp_dir() . "/transform_plugin/{$file}") < strtotime('-2 days')) {
                unlink(get_temp_dir() . "/transform_plugin/{$file}");
            }
        }
    }
    closedir($dp);
    return true;
}
开发者ID:perryrothjohnson,项目名称:resourcespace,代码行数:45,代码来源:transform_functions.php

示例5: explode

include "../../include/db.php";
include "../../include/general.php";
# Fetch a list of MySQL processes and kill any that exceed the timeout limit.
# Config vars
$query_timeout = 10;
# Timeout in seconds.
$sleep_timeout = 360;
#$mysql_path="/usr/local/mysql-standard-5.0.15-osx10.4-powerpc/bin/";
$mysql_path = "/usr/bin/";
$mysql_command = $mysql_path . "mysqladmin -h {$mysql_server} -u {$mysql_username} " . ($mysql_password == "" ? "" : "-p" . $mysql_password);
for ($s = 0; $s < 60; $s += 10) {
    # Fetch process list
    $list = explode("\n", run_command($mysql_command . " processlist"));
    #echo "<pre>";
    #print_r($list);
    for ($n = 3; $n < count($list) - 2; $n++) {
        $vals = explode("|", $list[$n]);
        $id = trim($vals[1]);
        $type = trim($vals[5]);
        $time = trim($vals[6]);
        $info = trim($vals[6]) . " : " . trim($vals[7]);
        $query = trim($vals[8]);
        if ($type == "Query" && $time > $query_timeout && (strpos($query, "select") !== false || strpos($query, "create temporary table") !== false) || $type == "Sleep" && $time > $sleep_timeout) {
            # Kill this process.
            echo "killing {$id}... {$info}\n";
            run_command($mysql_command . " kill " . $id);
        }
    }
    sleep(10);
}
开发者ID:vongalpha,项目名称:resourcespace,代码行数:30,代码来源:mysql_timeout.php

示例6: explode

     $s = explode(":", $r);
     $from = $s[0];
     $to = $s[1];
     if (getval("method", "") == "alternativefile") {
         $aref = add_alternative_file($ref, $lang["pages"] . " " . $from . " - " . $to, "", "", "pdf");
         $copy_path = get_resource_path($ref, true, "", true, "pdf", -1, 1, false, "", $aref);
     } else {
         # Create a new resource based upon the metadata/type of the current resource.
         $copy = copy_resource($ref);
         # Find out the path to the original file.
         $copy_path = get_resource_path($copy, true, "", true, "pdf");
     }
     # Extract this one page to a new resource.
     $ghostscript_fullpath = get_utility_path("ghostscript");
     $gscommand = $ghostscript_fullpath . " -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=" . escapeshellarg($copy_path) . "  -dFirstPage=" . $from . " -dLastPage=" . $to . " " . escapeshellarg($file);
     $output = run_command($gscommand);
     if (getval("method", "") == "alternativefile") {
         # Preview creation for alternative files (enabled via config)
         global $alternative_file_previews;
         if ($alternative_file_previews) {
             create_previews($ref, false, "pdf", false, false, $aref);
         }
         # Update size.
         sql_query("update resource_alt_files set file_size='" . filesize_unlimited($copy_path) . "' where ref='{$aref}'");
     } else {
         # Update the file extension
         sql_query("update resource set file_extension='pdf' where ref='{$copy}'");
         # Create preview for the page.
         create_previews($copy, false, "pdf");
     }
 }
开发者ID:chandradrupal,项目名称:resourcespace,代码行数:31,代码来源:pdf_split.php

示例7: preg_replace

    # Remove critical characters from filename
    $filename = preg_replace('/:/', '_', $filename);
    hook("downloadfilename");
    if (!$direct) {
        # We use quotes around the filename to handle filenames with spaces.
        header(sprintf('Content-Disposition: attachment; filename="%s"', $filename));
    }
}
# We assign a default mime-type, in case we can find the one associated to the file extension.
$mime = "application/octet-stream";
if ($noattach == "") {
    # Get mime type via exiftool if possible
    $exiftool_fullpath = get_utility_path("exiftool");
    if ($exiftool_fullpath != false) {
        $command = $exiftool_fullpath . " -s -s -s -t -mimetype " . escapeshellarg($path);
        $mime = run_command($command);
    }
    # Override or correct for lack of exiftool with config mappings
    if (isset($mime_type_by_extension[$ext])) {
        $mime = $mime_type_by_extension[$ext];
    }
}
# We declare the downloaded content mime type.
header("Content-Type: {$mime}");
set_time_limit(0);
#echo file_get_contents($path);
# The above required that the downloaded file was read into PHP's memory space first.
# Perhaps this is not the case for readfile().
# Old method
#readfile($path);
# New method
开发者ID:vongalpha,项目名称:resourcespace,代码行数:31,代码来源:download.php

示例8: exit

        exit();
    };

    //if user submitted a blank form?
    if ($file==''){
        $data['error'] = true;
        $data['success'] = false;
        $data['textStatus'] = 'Please Choose A Resource';
        echo(json_encode($data));
        exit();
    };

    $uploaddir = '/var/www/filestore/tmp/uploads/';
    $exiftool_fullpath = get_utility_path("exiftool");
    $command = $exiftool_fullpath . " -j --filename --exiftoolversion --filepermissions --NativeDigest --History --Directory " . escapeshellarg($uploaddir.$file)." 2>&1";
    $report_original = run_command($command);
    $extension = pathinfo($uploaddir.$file, PATHINFO_EXTENSION);
    $resource_type="";
    //get all of the available resource types and check the file extesion of uploaded file
    $resource_types=get_resource_types();
	//make sure file extension is all lowercase to ensure accurate match
    $file_extension = strtolower($extension);

    //for all of the resource types found
	for($i=0; $i<count($resource_types); $i++){
        //explode the allowed extensions into an array and remove any whitespaces
        $extension = preg_replace('/\s*/', '', $resource_types[$i]['allowed_extensions']);
        $resource_extensions=explode(',' , strtolower($extension));
        //check the array for the file extension
        if(in_array($file_extension,$resource_extensions)){
            //if the extension is found set the resource type for the found extension
开发者ID:artsmia,项目名称:mia_resourcespace,代码行数:31,代码来源:upload2.php

示例9: get_resource_path

 $file = get_resource_path($ref, true, "", false, $extension);
 $filesize = @filesize_unlimited($file);
 if (isset($imagemagick_path)) {
     # Check ImageMagick identify utility.
     $identify_fullpath = get_utility_path("im-identify");
     if ($identify_fullpath == false) {
         exit("Could not find ImageMagick 'identify' utility.");
     }
     $prefix = '';
     # Camera RAW images need prefix
     if (preg_match('/^(dng|nef|x3f|cr2|crw|mrw|orf|raf|dcr)$/i', $extension, $rawext)) {
         $prefix = $rawext[0] . ':';
     }
     # Get image's dimensions.
     $identcommand = $identify_fullpath . ' -format %wx%h ' . escapeshellarg($prefix . $file) . '[0]';
     $identoutput = run_command($identcommand);
     preg_match('/^([0-9]+)x([0-9]+)$/ims', $identoutput, $smatches);
     @(list(, $sw, $sh) = $smatches);
     if ($sw != '' && $sh != '') {
         $size_db = sql_query("select 'true' from resource_dimensions where resource = " . $ref);
         if (count($size_db)) {
             sql_query("update resource_dimensions set width=" . $sw . ", height=" . $sh . ", file_size='{$filesize}' where resource=" . $ref);
         } else {
             sql_query("insert into resource_dimensions (resource, width, height, file_size) values(" . $ref . ", " . $sw . ", " . $sh . ", '{$filesize}')");
         }
     }
 } else {
     # fetch source image size, if we fail, exit this function (file not an image, or file not a valid jpg/png/gif).
     if (!(@(list($sw, $sh) = @getimagesize($file)) === false)) {
         $size_db = sql_query("select 'true' from resource_dimensions where resource = " . $ref);
         if (count($size_db)) {
开发者ID:perryrothjohnson,项目名称:resourcespace,代码行数:31,代码来源:update_sizes.php

示例10: error_log

 if ($flip || $rotation > 0) {
     // assume we should reset exif orientation flag since they have rotated to another orientation
     $command .= " -orient undefined ";
 }
 $command .= $colorspace2;
 $command .= " \"{$newpath}\"";
 if ($cropper_debug && !$download && getval("slideshow", "") == "") {
     error_log($command);
     if (isset($_REQUEST['showcommand'])) {
         echo "{$command}";
         delete_alternative_file($ref, $newfile);
         exit;
     }
 }
 // fixme -- do we need to trap for errors from imagemagick?
 $shell_result = run_command($command);
 if ($cropper_debug) {
     error_log("SHELL RESULT: {$shell_result}");
 }
 // get final pixel dimensions of resulting file
 $newfilesize = filesize_unlimited($newpath);
 $newfiledimensions = getimagesize($newpath);
 $newfilewidth = $newfiledimensions[0];
 $newfileheight = $newfiledimensions[1];
 // generate previews if needed
 global $alternative_file_previews;
 if ($alternative_file_previews && !$download && !$original && getval("slideshow", "") == "") {
     create_previews($ref, false, $new_ext, false, false, $newfile);
 }
 // strip of any extensions from the filename, since we'll provide that
 if (preg_match("/(.*)\\.\\w\\w\\w\\\$/", $filename, $matches)) {
开发者ID:vongalpha,项目名称:resourcespace,代码行数:31,代码来源:crop.php

示例11: on_command

 public function on_command($pars)
 {
     $bundle_id = $this->stripFileName($pars['bundle']);
     $command = str_replace('..', '', $pars['command']);
     $command_path = $this->configuration['support-path'] . '/bundles/' . $bundle_id . '/commands/' . $command . '.amCommandDef';
     include_once $command_path;
     if (function_exists('run_command')) {
         run_command($this, $pars['text'], $pars);
         self::raiseError('Command returned no result.');
     } else {
         self::raiseError('Command not found.');
     }
 }
开发者ID:aprilchild,项目名称:aprilchild,代码行数:13,代码来源:amy_rexec.php

示例12: preg_replace

     if (!$config_windows) {
         $path = preg_replace('/\\r\\n/', "\n", $path);
     }
     fwrite($fh, $path);
     fclose($fh);
 }
 # Execute the archiver command.
 # If $collection_download is true the $collection_download_settings are used if defined, else the legacy $zipcommand is used.
 if ($use_zip_extension) {
     update_zip_progress_file("zipping");
     $wait = $zip->close();
     update_zip_progress_file("complete");
     sleep(1);
 } else {
     if ($archiver) {
         run_command($archiver_fullpath . " " . $collection_download_settings[$settings_id]["arguments"] . " " . escapeshellarg($zipfile) . " " . $archiver_listfile_argument . escapeshellarg($cmdfile));
     } else {
         if (!$use_zip_extension) {
             if ($config_windows) {
                 exec("{$zipcommand} " . escapeshellarg($zipfile) . " @" . escapeshellarg($cmdfile));
             } else {
                 # Pipe the command file, containing the filenames, to the executable.
                 exec("{$zipcommand} " . escapeshellarg($zipfile) . " -@ < " . escapeshellarg($cmdfile));
             }
         }
     }
 }
 # Archive created, schedule the command file for deletion.
 if (!$use_zip_extension) {
     $deletion_array[] = $cmdfile;
 }
开发者ID:chandradrupal,项目名称:resourcespace,代码行数:31,代码来源:collection_download.php

示例13: add_alternative_file

     }
     # Create the alternative file.
     $aref = add_alternative_file($ref, $ffmpeg_alternatives[$n]["name"]);
     $apath = get_resource_path($ref, true, "", true, $ffmpeg_alternatives[$n]["extension"], -1, 1, false, "", $aref);
     # Process the video
     $shell_exec_cmd = $ffmpeg_fullpath . "  {$ffmpeg_global_options} -y -i " . escapeshellarg($file) . " " . $ffmpeg_alternatives[$n]["params"] . " " . escapeshellarg($apath);
     $tmp = hook("ffmpegmodaltparams", "", array($shell_exec_cmd, $ffmpeg_fullpath, $file, $n, $aref));
     if ($tmp) {
         $shell_exec_cmd = $tmp;
     }
     $output = run_command($shell_exec_cmd);
     if (isset($qtfaststart_path)) {
         if ($qtfaststart_path && file_exists($qtfaststart_path . "/qt-faststart") && in_array($ffmpeg_alternatives[$n]["extension"], $qtfaststart_extensions)) {
             $apathtmp = $apath . ".tmp";
             rename($apath, $apathtmp);
             $output = run_command($qtfaststart_path . "/qt-faststart " . escapeshellarg($apathtmp) . " " . escapeshellarg($apath) . " 2>&1");
             unlink($apathtmp);
         }
     }
     if (file_exists($apath)) {
         # Update the database with the new file details.
         $file_size = filesize_unlimited($apath);
         # SQL Connection may have hit a timeout
         sql_connect();
         sql_query("update resource_alt_files set file_name='" . escape_check($ffmpeg_alternatives[$n]["filename"] . "." . $ffmpeg_alternatives[$n]["extension"]) . "',file_extension='" . escape_check($ffmpeg_alternatives[$n]["extension"]) . "',file_size='" . $file_size . "',creation_date=now() where ref='{$aref}'");
         // add this filename to be added to resource.ffmpeg_alt_previews
         if (isset($ffmpeg_alternatives[$n]['alt_preview']) && $ffmpeg_alternatives[$n]['alt_preview'] == true) {
             $ffmpeg_alt_previews[] = basename($apath);
         }
     }
 }
开发者ID:chandradrupal,项目名称:resourcespace,代码行数:31,代码来源:ffmpeg_processing.php

示例14: get_image_sizes

function get_image_sizes($ref,$internal=false,$extension="jpg",$onlyifexists=true)
	{
	# Returns a table of available image sizes for resource $ref. The standard image sizes are translated using $lang. Custom image sizes are i18n translated.
	# The original image file assumes the name of the 'nearest size (up)' in the table

	global $imagemagick_calculate_sizes;

	# Work out resource type
	$resource_type=sql_value("select resource_type value from resource where ref='$ref'","");

	# add the original image
	$return=array();
	$lastname=sql_value("select name value from preview_size where width=(select max(width) from preview_size)",""); # Start with the highest resolution.
	$lastpreview=0;$lastrestricted=0;
	$path2=get_resource_path($ref,true,'',false,$extension);

	if (file_exists($path2) && !checkperm("T" . $resource_type . "_"))
	{ 
		$returnline=array();
		$returnline["name"]=lang_or_i18n_get_translated($lastname, "imagesize-");
		$returnline["allow_preview"]=$lastpreview;
		$returnline["allow_restricted"]=$lastrestricted;
		$returnline["path"]=$path2;
		$returnline["id"]="";
		$dimensions = sql_query("select width,height,file_size,resolution,unit from resource_dimensions where resource=". $ref);
		
		if (count($dimensions))
			{
			$sw = $dimensions[0]['width']; if ($sw==0) {$sw="?";}
			$sh = $dimensions[0]['height']; if ($sh==0) {$sh="?";}
			$filesize=$dimensions[0]['file_size'];
			# resolution and unit are not necessarily available, set to empty string if so.
			$resolution = ($dimensions[0]['resolution'])?$dimensions[0]['resolution']:"";
			$unit = ($dimensions[0]['unit'])?$dimensions[0]['unit']:"";
			}
		else
			{
			global $imagemagick_path;
			$file=$path2;
			$filesize=filesize_unlimited($file);
			
			# imagemagick_calculate_sizes is normally turned off 
			if (isset($imagemagick_path) && $imagemagick_calculate_sizes)
				{
				# Use ImageMagick to calculate the size
				
				$prefix = '';
				# Camera RAW images need prefix
				if (preg_match('/^(dng|nef|x3f|cr2|crw|mrw|orf|raf|dcr)$/i', $extension, $rawext)) { $prefix = $rawext[0] .':'; }

				# Locate imagemagick.
                $identify_fullpath = get_utility_path("im-identify");
                if ($identify_fullpath==false) {exit("Could not find ImageMagick 'identify' utility at location '$imagemagick_path'.");}	
				# Get image's dimensions.
                $identcommand = $identify_fullpath . ' -format %wx%h '. escapeshellarg($prefix . $file) .'[0]';
				$identoutput=run_command($identcommand);
				preg_match('/^([0-9]+)x([0-9]+)$/ims',$identoutput,$smatches);
				@list(,$sw,$sh) = $smatches;
				if (($sw!='') && ($sh!=''))
				  {
					sql_query("insert into resource_dimensions (resource, width, height, file_size) values('". $ref ."', '". $sw ."', '". $sh ."', '" . $filesize . "')");
					}
				}	
			else 
				{
				# check if this is a raw file.	
				$rawfile = false;
				if (preg_match('/^(dng|nef|x3f|cr2|crw|mrw|orf|raf|dcr)$/i', $extension, $rawext)){$rawfile=true;}
					
				# Use GD to calculate the size
				if (!((@list($sw,$sh) = @getimagesize($file))===false)&& !$rawfile)
				 	{		
					sql_query("insert into resource_dimensions (resource, width, height, file_size) values('". $ref ."', '". $sw ."', '". $sh ."', '" . $filesize . "')");
					}
				else
					{
					# Size cannot be calculated.
					$sw="?";$sh="?";
					
					# Insert a dummy row to prevent recalculation on every view.
					sql_query("insert into resource_dimensions (resource, width, height, file_size) values('". $ref ."','0', '0', '" . $filesize . "')");
					}
				}
			}
		if (!is_numeric($filesize)) {$returnline["filesize"]="?";$returnline["filedown"]="?";}
		else {$returnline["filedown"]=ceil($filesize/50000) . " seconds @ broadband";$returnline["filesize"]=formatfilesize($filesize);}
		$returnline["width"]=$sw;			
		$returnline["height"]=$sh;
		$returnline["extension"]=$extension;
		(isset($resolution))?$returnline["resolution"]=$resolution:$returnline["resolution"]="";
		(isset($unit))?$returnline["unit"]=$unit:$returnline["unit"]="";
		$return[]=$returnline;
	}
	# loop through all image sizes
	$sizes=sql_query("select * from preview_size order by width desc");
	for ($n=0;$n<count($sizes);$n++)
		{
		$path=get_resource_path($ref,true,$sizes[$n]["id"],false,"jpg");

		$resource_type=sql_value("select resource_type value from resource where ref='$ref'","");
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:general.php

示例15: HookImagestreamUpload_pluploadInitialuploadprocessing

function HookImagestreamUpload_pluploadInitialuploadprocessing()
{
    #Support for uploading multi files as zip
    global $config_windows, $id, $targetDir, $resource_type, $imagestream_restypes, $imagestream_transitiontime, $zipcommand, $use_zip_extension, $userref, $session_hash, $filename, $filename_field, $collection_add, $archiver, $zipcommand, $ffmpeg_fullpath, $ffmpeg_preview_extension, $ffmpeg_preview_options, $ffmpeg_preview_min_height, $ffmpeg_preview_max_height, $ffmpeg_preview_min_width, $ffmpeg_preview_max_width, $lang, $collection_download_settings, $archiver_listfile_argument;
    $ffmpeg_fullpath = get_utility_path("ffmpeg");
    debug("DEBUG: Imagestream - checking restype: " . $resource_type . $imagestream_restypes);
    if (in_array($resource_type, $imagestream_restypes)) {
        debug("DEBUG: Imagestream - uploading file");
        #Check that we have an archiver configured
        $archiver_fullpath = get_utility_path("archiver");
        if (!isset($zipcommand) && !$use_zip_extension) {
            if ($archiver_fullpath == false) {
                exit($lang["archiver-utility-not-found"]);
            }
        }
        echo print_r($_POST) . print_r($_GET);
        if (getval("lastqueued", "")) {
            debug("DEBUG: Imagestream - last queued file");
            $ref = copy_resource(0 - $userref);
            # Copy from user template
            debug("DEBUG: Imagestream - creating resource: " . $ref);
            # Create the zip file
            $imagestreamzippath = get_resource_path($ref, true, "", true, "zip");
            if ($use_zip_extension) {
                $zip = new ZipArchive();
                $zip->open($imagestreamzippath, ZIPARCHIVE::CREATE);
            }
            $deletion_array = array();
            debug("DEBUG: opening directory: " . $targetDir);
            $imagestream_files = opendir($targetDir);
            $imagestream_workingfiles = get_temp_dir() . DIRECTORY_SEPARATOR . "plupload" . DIRECTORY_SEPARATOR . $session_hash . "workingfiles";
            if (!file_exists($imagestream_workingfiles)) {
                if ($config_windows) {
                    @mkdir($imagestream_workingfiles);
                } else {
                    @mkdir($imagestream_workingfiles, 0777, true);
                }
            }
            $filenumber = 00;
            $imagestream_filelist = array();
            while ($imagestream_filelist[] = readdir($imagestream_files)) {
                sort($imagestream_filelist);
            }
            closedir($imagestream_files);
            $imageindex = 1;
            foreach ($imagestream_filelist as $imagestream_file) {
                if ($imagestream_file != '.' && $imagestream_file != '..') {
                    $filenumber = sprintf("%03d", $filenumber);
                    $deletion_array[] = $targetDir . DIRECTORY_SEPARATOR . $imagestream_file;
                    if (!$use_zip_extension) {
                        $imagestreamcmd_file = get_temp_dir(false, $id) . "/imagestreamzipcmd" . $imagestream_file . ".txt";
                        $fh = fopen($imagestreamcmd_file, 'w') or die("can't open file");
                        fwrite($fh, $targetDir . DIRECTORY_SEPARATOR . $imagestream_file . "\r\n");
                        fclose($fh);
                        $deletion_array[] = $imagestreamcmd_file;
                    }
                    if ($use_zip_extension) {
                        debug("DEBUG: Imagestream - adding filename: " . $imagestream_file);
                        debug("DEBUG: using zip PHP extension, set up zip at : " . $imagestreamzippath);
                        $zip->addFile($imagestream_file);
                        debug(" Added files number : " . $zip->numFiles);
                        $wait = $zip->close();
                        debug("DEBUG: closed zip");
                    } else {
                        if ($archiver_fullpath) {
                            debug("DEBUG: using archiver, running command: \r\n" . $archiver_fullpath . " " . $collection_download_settings[0]["arguments"] . " " . escapeshellarg($imagestreamzippath) . " " . $archiver_listfile_argument . escapeshellarg($imagestream_file));
                            run_command($archiver_fullpath . " " . $collection_download_settings[0]["arguments"] . " " . escapeshellarg($imagestreamzippath) . " " . $archiver_listfile_argument . escapeshellarg($imagestreamcmd_file));
                        } else {
                            if (!$use_zip_extension) {
                                if ($config_windows) {
                                    debug("DEBUG: using zip command: . {$zipcommand} " . escapeshellarg($imagestreamzippath) . " @" . escapeshellarg($imagestreamcmd_file));
                                    exec("{$zipcommand} " . escapeshellarg($imagestreamzippath) . " @" . escapeshellarg($imagestreamcmd_file));
                                } else {
                                    # Pipe the command file, containing the filenames, to the executable.
                                    exec("{$zipcommand} " . escapeshellarg($imagestreamzippath) . " -@ < " . escapeshellarg($imagestreamcmd_file));
                                }
                            }
                        }
                    }
                    #Create a JPEG if not already in that format
                    $imagestream_file_parts = explode('.', $imagestream_file);
                    $imagestream_file_ext = $imagestream_file_parts[count($imagestream_file_parts) - 1];
                    $imagestream_file_noext = basename($imagestream_file, $imagestream_file_ext);
                    global $imagemagick_path, $imagemagick_quality;
                    $icc_transform_complete = false;
                    # Camera RAW images need prefix
                    if (preg_match('/^(dng|nef|x3f|cr2|crw|mrw|orf|raf|dcr)$/i', $imagestream_file_ext, $rawext)) {
                        $prefix = $rawext[0] . ':';
                    }
                    # Locate imagemagick.
                    $convert_fullpath = get_utility_path("im-convert");
                    if ($convert_fullpath == false) {
                        exit("Could not find ImageMagick 'convert' utility at location '{$imagemagick_path}'.");
                    }
                    $prefix = '';
                    if ($prefix == "cr2:" || $prefix == "nef:") {
                        $flatten = "";
                    } else {
                        $flatten = "-flatten";
                    }
//.........这里部分代码省略.........
开发者ID:chandradrupal,项目名称:resourcespace,代码行数:101,代码来源:upload_plupload.php


注:本文中的run_command函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。