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


PHP Media::set方法代码示例

本文整理汇总了PHP中Media::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Media::set方法的具体用法?PHP Media::set怎么用?PHP Media::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Media的用法示例。


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

示例1: write

 /**
  * @param array $pa_options Options include:
  *		dontUseDefaultIcons = If set to true, write will fail rather than use default icons when preview can't be generated. Default is false – to use default icons.
  *
  */
 public function write($ps_filepath, $ps_mimetype, $pa_options = null)
 {
     if (!$this->handle) {
         return false;
     }
     $vb_dont_allow_default_icons = isset($pa_options['dontUseDefaultIcons']) && $pa_options['dontUseDefaultIcons'] ? true : false;
     # is mimetype valid?
     if (!($vs_ext = $this->info["EXPORT"][$ps_mimetype])) {
         $this->postError(1610, _t("Can't convert file to %1", $ps_mimetype), "WLPlugPDFWand->write()");
         return false;
     }
     # write the file
     if ($ps_mimetype == "application/pdf") {
         if (!copy($this->filepath, $ps_filepath . ".pdf")) {
             $this->postError(1610, _t("Couldn't write file to '%1'", $ps_filepath), "WLPlugPDFWand->write()");
             return false;
         }
     } else {
         $vb_use_default_icon = true;
         if (caMediaPluginGhostscriptInstalled($this->ops_ghostscript_path)) {
             $vn_scaling_correction = $this->get("scaling_correction");
             $vs_res = "72x72";
             if (ceil($this->get("resolution")) > 0) {
                 $vn_res = $this->get("resolution");
                 if ($vn_scaling_correction) {
                     $vn_res *= 2;
                 }
                 $vs_res = ceil($vn_res) . "x" . ceil($vn_res);
             }
             $vn_page = ceil($this->get("page"));
             $vn_quality = ceil($this->get("quality"));
             if ($vn_quality > 100) {
                 $vn_quality = 100;
             }
             if ($vn_quality < 1) {
                 $vn_quality = 50;
             }
             if ($vn_page < 1) {
                 $vn_page = 1;
             }
             if ($this->get("antialiasing")) {
                 $vs_antialiasing = "-dTextAlphaBits=4 -dGraphicsAlphaBits=4";
             } else {
                 $vs_antialiasing = "";
             }
             $vb_processed_preview = false;
             switch ($ps_mimetype) {
                 case 'image/jpeg':
                     exec($this->ops_ghostscript_path . " -dNOPAUSE -dBATCH -sDEVICE=" . ($vn_scaling_correction ? "tiff24nc" : "jpeg") . " {$vs_antialiasing} -dJPEGQ=" . $vn_quality . " -dFirstPage=" . $vn_page . " -dLastPage=" . $vn_page . " -sOutputFile=" . caEscapeShellArg($ps_filepath . "." . $vs_ext) . " -r" . $vs_res . " " . caEscapeShellArg($this->handle["filepath"]), $va_output, $vn_return);
                     if ($vn_return == 0) {
                         $vb_processed_preview = true;
                     }
                     break;
                 case 'image/tiff':
                 case 'image/png':
                 case 'image/gif':
                     exec($this->ops_ghostscript_path . " -dNOPAUSE -dBATCH -sDEVICE=tiff24nc {$vs_antialiasing} -dFirstPage=" . $vn_page . " -dLastPage=" . $vn_page . " -sOutputFile=" . caEscapeShellArg($ps_filepath . "." . $vs_ext) . " -r" . $vs_res . " " . caEscapeShellArg($this->handle["filepath"]), $va_output, $vn_return);
                     if ($vn_return == 0) {
                         $vb_processed_preview = true;
                     }
                     break;
                 default:
                     //die("Unsupported output type in PDF plug-in: $ps_mimetype [this shouldn't happen]");
                     break;
             }
             if ($vb_processed_preview) {
                 if ($vs_crop = $this->get("crop")) {
                     $o_media = new Media();
                     list($vn_w, $vn_h) = explode("x", $vs_crop);
                     if ($vn_w > 0 && $vn_h > 0) {
                         $o_media->read($ps_filepath . "." . $vs_ext);
                         if (!$o_media->numErrors()) {
                             $o_media->transform('SCALE', array('mode' => 'fill_box', 'antialiasing' => 0.5, 'width' => $vn_w, 'height' => $vn_h));
                             $o_media->write($ps_filepath, $ps_mimetype, array());
                             if (!$o_media->numErrors()) {
                                 $this->properties["width"] = $vn_w;
                                 $this->properties["height"] = $vn_h;
                                 $vb_use_default_icon = false;
                             }
                         }
                     }
                 } else {
                     if ($vn_scaling_correction) {
                         $o_media = new Media(true);
                         $o_media->read($ps_filepath . "." . $vs_ext);
                         if (!$o_media->numErrors()) {
                             $vn_w = $o_media->get('width') * $vn_scaling_correction;
                             $vn_h = $o_media->get('height') * $vn_scaling_correction;
                             if ($vn_w > $vn_h || $this->get("target_height") == 0) {
                                 $vn_r = $this->get("target_width") / $vn_w;
                                 $vn_w = $this->get("target_width");
                                 $vn_h *= $vn_r;
                             } else {
                                 $vn_r = $this->get("target_height") / $vn_h;
                                 $vn_h = $this->get("target_height");
//.........这里部分代码省略.........
开发者ID:guaykuru,项目名称:pawtucket,代码行数:101,代码来源:PDFWand.php

示例2: cacheThumbnail

		function cacheThumbnail($itemId, $item) {
			global $database, $db;
			if (!isset($item) || !is_array($item) || !defined('ROOT') || !isset($itemId) || !Validator::getBool($itemId))
				return false;

			$cacheDir = ROOT. '/cache/thumbnail';
			if (!is_dir($cacheDir)) func::mkpath($cacheDir);
			if (!is_writeable($cacheDir)) return false;

			$division = ord(substr(str_replace("http://","",$item['permalink']), 0, 1));

			requireComponent('LZ.PHP.Media');
			$media = new Media;
			$media->set('outputPath', $cacheDir.'/'.$division);

			$item['id'] = $itemId; // for uniqueId

			list($thumbnailLimit, $thumbnailSize, $thumbnailType) = Settings::gets('thumbnailLimit, thumbnailSize, thumbnailType');
			if($thumbnailLimit == 0) return false;

			if (!$result = $media->get($item, $thumbnailSize, $thumbnailLimit, $thumbnailType))
				return false;

			foreach($result['movies'] as $m_item) {
				$tFilename = $db->escape(str_replace($cacheDir, '', $m_item['filename']['fullpath']));
				$tSource = $db->escape($m_item['source']);

				if(!empty($tFilename)) {
					$width = $m_item['width'];
					$height = $m_item['height'];
					$via = $m_item['via'];					
					$insertId = $media->add($itemId, $tFilename, $tSource, $width, $height, 'movie', $via);
				}
			}

			foreach($result['images'] as $i_item) {
				$tFilename = $db->escape(str_replace($cacheDir, '', $i_item['filename']['fullpath']));
				$tSource = $db->escape($i_item['source']);

				if(!empty($tFilename) && $i_item['width'] > 100 && $i_item['height'] > 100) {
					$width = $i_item['width'];
					$height = $i_item['height'];
					$insertId = $media->add($itemId, $tFilename, $tSource, $width, $height, 'image');
				}
			}
	
			if(isset($insertId)) {
				$db->execute("UPDATE {$database['prefix']}FeedItems SET thumbnailId='$insertId' WHERE id='$itemId'");
			}

			return true;
		}
开发者ID:ncloud,项目名称:bloglounge,代码行数:52,代码来源:Bloglounge.Data.FeedItems.php

示例3: process

 /**
  * Method invoked when the task queue needs to actually execute the task. For mediaproc this means
  * actually doing the processing of media!
  *
  * Return false on failure/error and sets the error property with an error description. Returns an array
  * with processing details on success.
  *
  * @param array $pa_parameters An unserialized parameters array for the current task (eg. unserialized data from ca_task_queue.parameters)
  * @return array Returns false on error, or an array with processing details on success
  */
 public function process($pa_parameters)
 {
     $vs_table = $pa_parameters["TABLE"];
     // name of table of record we're processing
     $vs_field = $pa_parameters["FIELD"];
     // name of field in record we're processing
     $vs_pk = $pa_parameters["PK"];
     // Field name of primary key of record we're processing
     $vn_id = $pa_parameters["PK_VAL"];
     // Value of primary key
     $vs_input_mimetype = $pa_parameters["INPUT_MIMETYPE"];
     // Mimetype of input file
     $vs_input_file = $pa_parameters["FILENAME"];
     // Full path to input file
     // Array of media versions to process; keys are version names,
     // values are arrays with info about processing for that version
     // Currently the info array contains a single key, 'VOLUME', which indicates
     // the volume the version should be written to
     $va_versions = $pa_parameters["VERSIONS"];
     $va_options = $pa_parameters["OPTIONS"];
     // Array of processing options; names of options to employ are keys, settings are values
     // If true, then input media is *not* deleted
     $vb_dont_delete_original_media = (bool) $pa_parameters["DONT_DELETE_OLD_MEDIA"];
     $va_report = array('errors' => array(), 'notes' => array());
     $o_dm = Datamodel::load();
     $o_media_volumes = new MediaVolumes();
     $o_media = new Media();
     $o_media_proc_settings = new MediaProcessingSettings($vs_table, $vs_field);
     $vs_media_type = $o_media_proc_settings->canAccept($vs_input_mimetype);
     $va_version_info = $o_media_proc_settings->getMediaTypeVersions($vs_media_type);
     if (!file_exists($vs_input_file)) {
         $o_eventlog = new EventLog();
         $o_eventlog->log(array("CODE" => "DEBG", "SOURCE" => "TaskQueue->mediaproc->process()", "MESSAGE" => "Record {$vs_table}.field = file '{$vs_input_file}' did not exist; queued file was discarded"));
         $va_report['errors'][] = _t("Record %1.field = file '%2' did not exist; queued file was discarded", $vs_table, $vs_input_file);
         return $va_report;
     }
     if ($t_instance = $o_dm->getInstanceByTableName($vs_table, true)) {
         if ($t_instance->hasField($vs_field)) {
             if (!$t_instance->load($vn_id)) {
                 # record no longer exists
                 if (!$vb_dont_delete_original_media) {
                     @unlink($vs_input_file);
                 }
                 $o_eventlog = new EventLog();
                 $o_eventlog->log(array("CODE" => "DEBG", "SOURCE" => "TaskQueue->mediaproc->process()", "MESSAGE" => "Record {$vs_table}.field = {$vn_id} did not exist; queued file was discarded"));
                 $o_media->cleanup();
                 $va_report['errors'][] = _t("Record %1.field = %2 did not exist; queued file was discarded", $vs_table, $vn_id);
                 return $va_report;
             }
         } else {
             # bad field name
             $this->error->setError(551, _t("Invalid media field '%1' in table '%2'", $vs_field, $vs_table), "mediaproc->process()");
             return false;
         }
     } else {
         # bad table name
         $this->error->setError(550, _t("Invalid media field table '%1'", $vs_table), "mediaproc->process()");
         return false;
     }
     $va_old_media_to_delete = array();
     foreach ($va_versions as $v => $va_version_settings) {
         $vs_use_icon = null;
         if (!file_exists($vs_input_file)) {
             $this->error->setError(505, _t("Input media file '%1' does not exist", $vs_input_file), "mediaproc->process()");
             $o_media->cleanup();
             return false;
         }
         if (!is_readable($vs_input_file)) {
             $this->error->setError(506, _t("Denied permission to read input media file '%1'", $vs_input_file), "mediaproc->process()");
             $o_media->cleanup();
             return false;
         }
         if (!$o_media->read($vs_input_file)) {
             $this->error->setError(1600, _t("Could not process input media file '%1': %2", $vs_input_file, join('; ', $o_media->getErrors())), "mediaproc->process()");
             $o_media->cleanup();
             return false;
         }
         $vs_rule = isset($va_version_info[$v]['RULE']) ? $va_version_info[$v]['RULE'] : '';
         $va_rules = $o_media_proc_settings->getMediaTransformationRule($vs_rule);
         $va_volume_info = $o_media_volumes->getVolumeInformation($va_version_settings['VOLUME']);
         if (sizeof($va_rules) == 0) {
             $vs_output_mimetype = $vs_input_mimetype;
             #
             # don't process this media, just copy the file
             #
             $vs_ext = $o_media->mimetype2extension($vs_output_mimetype);
             if (!$vs_ext) {
                 $this->error->setError(1600, _t("File could not be copied for %1; can't convert mimetype %2 to extension", $vs_field, $vs_output_mimetype), "mediaproc->process()");
                 $o_media->cleanup();
                 return false;
//.........这里部分代码省略.........
开发者ID:idiscussforum,项目名称:providence,代码行数:101,代码来源:mediaproc.php

示例4: write

 /**
  * @param array $pa_options Options include:
  *		dontUseDefaultIcons = If set to true, write will fail rather than use default icons when preview can't be generated. Default is false – to use default icons.
  *
  */
 public function write($ps_filepath, $ps_mimetype, $pa_options = null)
 {
     if (!$this->handle) {
         return false;
     }
     $vb_dont_allow_default_icons = isset($pa_options['dontUseDefaultIcons']) && $pa_options['dontUseDefaultIcons'] ? true : false;
     # is mimetype valid?
     if (!($vs_ext = $this->info["EXPORT"][$ps_mimetype])) {
         $this->postError(1610, _t("Can't convert file to %1", $ps_mimetype), "WLPlugMediaOffice->write()");
         return false;
     }
     # write the file
     if ($ps_mimetype == "application/msword") {
         if (!copy($this->filepath, $ps_filepath . ".doc")) {
             $this->postError(1610, _t("Couldn't write file to '%1'", $ps_filepath), "WLPlugMediaOffice->write()");
             return false;
         }
     } else {
         if (!isset(WLPlugMediaOffice::$s_pdf_conv_cache[$this->filepath]) && $this->opb_libre_office_installed) {
             $vs_tmp_dir_path = caGetTempDirPath();
             $va_tmp = explode("/", $this->filepath);
             $vs_out_file = array_pop($va_tmp);
             putenv("HOME={$vs_tmp_dir_path}");
             // libreoffice will fail silently if you don't set this environment variable to a directory it can write to. Nice way to waste a day debugging. Yay!
             exec($this->ops_libreoffice_path . " --nologo --nofirststartwizard --headless -convert-to pdf " . caEscapeShellArg($this->filepath) . "  -outdir " . caEscapeShellArg($vs_tmp_dir_path) . " 2>&1", $va_output, $vn_return);
             exec($this->ops_libreoffice_path . " --nologo --nofirststartwizard --headless -convert-to html " . caEscapeShellArg($this->filepath) . "  -outdir " . caEscapeShellArg($vs_tmp_dir_path) . " 2>&1", $va_output, $vn_return);
             $va_out_file = explode(".", $vs_out_file);
             if (sizeof($va_out_file) > 1) {
                 array_pop($va_out_file);
             }
             $this->handle['content'] = strip_tags(file_get_contents("{$vs_tmp_dir_path}/" . join(".", $va_out_file) . ".html"));
             $va_out_file[] = 'pdf';
             WLPlugMediaOffice::$s_pdf_conv_cache[$this->filepath] = "{$vs_tmp_dir_path}/" . join(".", $va_out_file);
             $o_media = new Media();
             if ($o_media->read(WLPlugMediaOffice::$s_pdf_conv_cache[$this->filepath])) {
                 $this->set('width', $this->ohandle["width"] = $o_media->get('width'));
                 $this->set('height', $this->ohandle["height"] = $o_media->get('height'));
                 $this->set('resolution', $this->ohandle["resolution"] = $o_media->get('resolution'));
             }
         }
         if ($vs_media = WLPlugMediaOffice::$s_pdf_conv_cache[$this->filepath]) {
             switch ($ps_mimetype) {
                 case 'application/pdf':
                     $o_media = new Media();
                     $o_media->read($vs_media);
                     $o_media->set('version', $this->get('version'));
                     $o_media->write($ps_filepath, $ps_mimetype, array());
                     $vs_filepath_with_extension = $ps_filepath . ".pdf";
                     break;
                 case 'image/jpeg':
                     $o_media = new Media();
                     $o_media->read($vs_media);
                     $o_media->set('version', $this->get('version'));
                     foreach ($this->opa_transformations as $va_transform) {
                         $o_media->transform($va_transform['op'], $va_transform['params']);
                     }
                     $o_media->write($ps_filepath, $ps_mimetype, array());
                     $this->set('width', $o_media->get('width'));
                     $this->set('height', $o_media->get('height'));
                     $vs_filepath_with_extension = $ps_filepath . ".jpg";
                     break;
             }
         }
         # use default media icons
         if (!file_exists($vs_filepath_with_extension)) {
             // always jpegs
             return $vb_dont_allow_default_icons ? null : __CA_MEDIA_DOCUMENT_DEFAULT_ICON__;
         }
     }
     $this->properties["mimetype"] = $ps_mimetype;
     $this->properties["filesize"] = filesize($ps_filepath . "." . $vs_ext);
     //$this->properties["typename"] = $this->typenames[$ps_mimetype];
     return $ps_filepath . "." . $vs_ext;
 }
开发者ID:guaykuru,项目名称:pawtucket,代码行数:79,代码来源:Office.php


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