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


PHP Media::write方法代码示例

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


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

示例1: applyMediaTransformation

 /**
  * Apply media transformation to media in specified field of current loaded row. When a transformation is applied
  * it is applied to all versions, including the "original." A copy of the original is stashed in a "virtual" version named "_undo_"
  * to make it possible to recover the original media, if desired, by calling removeMediaTransformations().
  *
  * @param string $ps_field The name of the media field
  * @param string $ps_op A valid media transformation op code, as defined by the media plugin handling the media being transformed.
  * @param array $pa_params The parameters for the op code, as defined by the media plugin handling the media being transformed.
  * @param array $pa_options An array of options. No options are currently implemented.
  *
  * @return bool True on success, false if an error occurred.
  */
 public function applyMediaTransformation($ps_field, $ps_op, $pa_params, $pa_options = null)
 {
     $va_media_info = $this->getMediaInfo($ps_field);
     if (!is_array($va_media_info)) {
         return null;
     }
     if (isset($pa_options['revert']) && $pa_options['revert'] && isset($va_media_info['_undo_'])) {
         $vs_path = $vs_undo_path = $this->getMediaPath($ps_field, '_undo_');
         $va_transformation_history = array();
     } else {
         $vs_path = $this->getMediaPath($ps_field, 'original');
         // Copy original into "undo" slot (if undo slot is empty)
         $vs_undo_path = !isset($va_media_info['_undo_']) ? $vs_path : $this->getMediaPath($ps_field, '_undo_');
         if (!is_array($va_transformation_history = $va_media_info['TRANSFORMATION_HISTORY'])) {
             $va_transformation_history = array();
         }
     }
     // TODO: Check if transformation valid for this media
     // Apply transformation to original
     $o_media = new Media();
     $o_media->read($vs_path);
     $o_media->transform($ps_op, $pa_params);
     $va_transformation_history[$ps_op][] = $pa_params;
     $vs_tmp_basename = tempnam(caGetTempDirPath(), 'ca_media_rotation_tmp');
     $o_media->write($vs_tmp_basename, $o_media->get('mimetype'), array());
     // Regenerate derivatives
     $this->setMode(ACCESS_WRITE);
     $this->set($ps_field, $vs_tmp_basename . "." . $va_media_info['original']['EXTENSION'], $vs_undo_path ? array('undo' => $vs_undo_path, 'TRANSFORMATION_HISTORY' => $va_transformation_history) : array('TRANSFORMATION_HISTORY' => $va_transformation_history));
     $this->setAsChanged($ps_field);
     $this->update();
     return $this->numErrors() ? false : true;
 }
开发者ID:samrahman,项目名称:providence,代码行数:44,代码来源:BaseModel.php

示例2: write

 public function write($filepath, $mimetype, $pa_options = null)
 {
     if (!$this->handle) {
         return false;
     }
     if (!($ext = $this->info["EXPORT"][$mimetype])) {
         # this plugin can't write this mimetype
         return false;
     }
     # is mimetype valid?
     switch ($mimetype) {
         # ------------------------------------
         case 'image/jpeg':
             $vn_preview_width = $this->properties["width"];
             $vn_preview_height = $this->properties["height"];
             if (caMediaPluginFFfmpegInstalled($this->ops_path_to_ffmpeg)) {
                 if (($vn_start_secs = $this->properties["duration"] / 8) > 120) {
                     $vn_start_secs = 120;
                     // always take a frame from the first two minutes to ensure performance (ffmpeg gets slow if it has to seek far into a movie to extract a frame)
                 }
                 exec($this->ops_path_to_ffmpeg . " -ss " . $vn_start_secs . " -i " . caEscapeShellArg($this->filepath) . " -f mjpeg -t 0.001 -y " . caEscapeShellArg($filepath . "." . $ext), $va_output, $vn_return);
                 if ($vn_return < 0 || $vn_return > 1 || !@filesize($filepath . "." . $ext)) {
                     @unlink($filepath . "." . $ext);
                     // don't throw error as ffmpeg cannot generate frame still from all files
                 } else {
                     // resize image to desired dimensions
                     $o_media = new Media();
                     $o_media->read($filepath . "." . $ext);
                     $o_media->transform('SCALE', array('width' => $vn_preview_width, 'height' => $vn_preview_height, 'mode' => 'bounding_box', 'antialiasing' => 0.5));
                     $o_media->write($filepath . "_tmp", 'image/jpeg', array());
                     if (!$o_media->numErrors()) {
                         rename($filepath . "_tmp." . $ext, $filepath . "." . $ext);
                     } else {
                         @unlink($filepath . "_tmp." . $ext);
                     }
                 }
             }
             // if output file doesn't exist, ffmpeg failed or isn't installed
             // so use default icons
             if (!file_exists($filepath . "." . $ext)) {
                 return __CA_MEDIA_VIDEO_DEFAULT_ICON__;
             }
             $this->properties["mimetype"] = $mimetype;
             $this->properties["typename"] = isset($this->typenames[$mimetype]) ? $this->typenames[$mimetype] : $mimetype;
             break;
             # ------------------------------------
         # ------------------------------------
         default:
             if ($mimetype != $this->handle["mime_type"]) {
                 # this plugin can't write this mimetype (no conversions allowed)
                 $this->postError(1610, _t("Can't convert '%1' to %2", $this->handle["mime_type"], $mimetype), "WLPlugQuicktimeVR->write()");
                 return false;
             }
             # write the file
             if (!copy($this->filepath, $filepath . "." . $ext)) {
                 $this->postError(1610, _t("Couldn't write file to '%1'", $filepath), "WLPlugQuicktimeVR->write()");
                 return false;
             }
             break;
             # ------------------------------------
     }
     return $filepath . "." . $ext;
 }
开发者ID:ffarago,项目名称:pawtucket2,代码行数:63,代码来源:QuicktimeVR.php

示例3: process


//.........这里部分代码省略.........
             $o_media->set('version', $v);
             while (list($operation, $pa_parameters) = each($va_rules)) {
                 if ($operation === 'SET') {
                     foreach ($pa_parameters as $pp => $pv) {
                         if ($pp == 'format') {
                             $vs_output_mimetype = $pv;
                         } else {
                             $o_media->set($pp, $pv);
                         }
                     }
                 } else {
                     if (!$o_media->transform($operation, $pa_parameters)) {
                         $this->error = $o_media->errors[0];
                         $o_media->cleanup();
                         return false;
                     }
                 }
             }
             if (!$vs_output_mimetype) {
                 $vs_output_mimetype = $vs_input_mimetype;
             }
             if (!($vs_ext = $o_media->mimetype2extension($vs_output_mimetype))) {
                 $this->error->setError(1600, _t("File could not be processed for %1; can't convert mimetype %2 to extension", $vs_field, $vs_output_mimetype), "mediaproc->process()");
                 $o_media->cleanup();
                 return false;
             }
             if (($vs_dirhash = $this->_getDirectoryHash($va_volume_info["absolutePath"], $vn_id)) === false) {
                 $this->error->setError(1600, _t("Couldn't create subdirectory for file for %1", $vs_field), "mediaproc->process()");
                 $o_media->cleanup();
                 return false;
             }
             $vs_magic = rand(0, 99999);
             $vs_filepath = $va_volume_info["absolutePath"] . "/" . $vs_dirhash . "/" . $vs_magic . "_" . $vs_table . "_" . $vs_field . "_" . $vn_id . "_" . $v;
             if (!($vs_output_file = $o_media->write($vs_filepath, $vs_output_mimetype, $va_options))) {
                 $this->error = $o_media->errors[0];
                 $o_media->cleanup();
                 return false;
             } else {
                 if ($vs_output_file === __CA_MEDIA_VIDEO_DEFAULT_ICON__ || $vs_output_file === __CA_MEDIA_AUDIO_DEFAULT_ICON__ || $vs_output_file === __CA_MEDIA_DOCUMENT_DEFAULT_ICON__) {
                     $vs_use_icon = $vs_output_file;
                 } else {
                     $va_output_files[] = $vs_output_file;
                 }
             }
             if (is_array($va_volume_info["mirrors"]) && sizeof($va_volume_info["mirrors"]) > 0) {
                 $entity_key = join("/", array($vs_table, $vs_field, $vn_id, $v));
                 $row_key = join("/", array($vs_table, $vn_id));
                 foreach ($va_volume_info["mirrors"] as $vs_mirror_code => $va_mirror_info) {
                     $vs_mirror_method = $va_mirror_info["method"];
                     $vs_queue = $vs_mirror_method . "mirror";
                     $tq = new TaskQueue();
                     if (!$tq->cancelPendingTasksForEntity($entity_key)) {
                         $this->error->setError(560, _t("Could not cancel pending tasks"), "mediaproc->process()");
                         $o_media->cleanup();
                         return false;
                     }
                     if ($tq->addTask($vs_queue, array("MIRROR" => $vs_mirror_code, "VOLUME" => $va_version_settings['VOLUME'], "FIELD" => $vs_field, "TABLE" => $vs_table, "VERSION" => $v, "FILES" => array(array("FILE_PATH" => $vs_filepath, "ABS_PATH" => $va_volume_info["absolutePath"], "HASH" => $vs_dirhash, "FILENAME" => $vs_magic . "_" . $vs_table . "_" . $vs_field . "_" . $vn_id . "_" . $v . "." . $vs_ext)), "MIRROR_INFO" => $va_mirror_info, "PK" => $vs_pk, "PK_VAL" => $vn_id), array("priority" => 100, "entity_key" => $entity_key, "row_key" => $row_key))) {
                         continue;
                     } else {
                         $this->error->setError(100, _t("Couldn't queue mirror using '%1' for version '%2' (handler '%3')", $vs_mirror_method, $v, $vs_queue), "mediaproc->process()");
                     }
                 }
             }
             if ($vs_use_icon) {
                 $media_desc[$v] = array("MIMETYPE" => $vs_output_mimetype, "USE_ICON" => $vs_use_icon, "WIDTH" => $o_media->get("width"), "HEIGHT" => $o_media->get("height"));
             } else {
开发者ID:idiscussforum,项目名称:providence,代码行数:67,代码来源: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), "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

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