本文整理汇总了PHP中Media::read方法的典型用法代码示例。如果您正苦于以下问题:PHP Media::read方法的具体用法?PHP Media::read怎么用?PHP Media::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Media
的用法示例。
在下文中一共展示了Media::read方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: reindex_pdfs
/**
* Reindex PDF media by content for in-PDF search
*/
public static function reindex_pdfs($po_opts = null)
{
require_once __CA_LIB_DIR__ . "/core/Db.php";
require_once __CA_MODELS_DIR__ . "/ca_object_representations.php";
if (!caPDFMinerInstalled()) {
CLIUtils::addError(_t("Can't reindex PDFs: PDFMiner is not installed."));
return false;
}
$o_db = new Db();
$t_rep = new ca_object_representations();
$t_rep->setMode(ACCESS_WRITE);
$va_versions = array("original");
$va_kinds = ($vs_kinds = $po_opts->getOption("kinds")) ? explode(",", $vs_kinds) : array();
if (!is_array($va_kinds) || !sizeof($va_kinds)) {
$va_kinds = array('all');
}
$va_kinds = array_map('strtolower', $va_kinds);
if (in_array('all', $va_kinds) || in_array('ca_object_representations', $va_kinds)) {
if (!($vn_start = (int) $po_opts->getOption('start_id'))) {
$vn_start = null;
}
if (!($vn_end = (int) $po_opts->getOption('end_id'))) {
$vn_end = null;
}
if ($vn_id = (int) $po_opts->getOption('id')) {
$vn_start = $vn_id;
$vn_end = $vn_id;
}
$va_ids = array();
if ($vs_ids = (string) $po_opts->getOption('ids')) {
if (sizeof($va_tmp = explode(",", $vs_ids))) {
foreach ($va_tmp as $vn_id) {
if ((int) $vn_id > 0) {
$va_ids[] = (int) $vn_id;
}
}
}
}
$vs_sql_where = null;
$va_params = array();
if (sizeof($va_ids)) {
$vs_sql_where = "WHERE representation_id IN (?)";
$va_params[] = $va_ids;
} else {
if ($vn_start > 0 && $vn_end > 0 && $vn_start <= $vn_end || $vn_start > 0 && $vn_end == null) {
$vs_sql_where = "WHERE representation_id >= ?";
$va_params[] = $vn_start;
if ($vn_end) {
$vs_sql_where .= " AND representation_id <= ?";
$va_params[] = $vn_end;
}
}
}
if ($vs_sql_where) {
$vs_sql_where .= " AND mimetype = 'application/pdf'";
} else {
$vs_sql_where = " WHERE mimetype = 'application/pdf'";
}
$qr_reps = $o_db->query("\n\t\t\t\t\tSELECT * \n\t\t\t\t\tFROM ca_object_representations \n\t\t\t\t\t{$vs_sql_where}\n\t\t\t\t\tORDER BY representation_id\n\t\t\t\t", $va_params);
print CLIProgressBar::start($qr_reps->numRows(), _t('Reindexing PDF representations'));
$vn_rep_table_num = $t_rep->tableNum();
while ($qr_reps->nextRow()) {
$va_media_info = $qr_reps->getMediaInfo('media');
$vs_original_filename = $va_media_info['ORIGINAL_FILENAME'];
print CLIProgressBar::next(1, _t("Reindexing PDF %1", $vs_original_filename ? $vs_original_filename . " (" . $qr_reps->get('representation_id') . ")" : $qr_reps->get('representation_id')));
$t_rep->load($qr_reps->get('representation_id'));
$vn_rep_id = $t_rep->getPrimaryKey();
$m = new Media();
if ($m->read($vs_path = $t_rep->getMediaPath('media', 'original')) && is_array($va_locs = $m->getExtractedTextLocations())) {
MediaContentLocationIndexer::clear($vn_rep_table_num, $vn_rep_id);
foreach ($va_locs as $vs_content => $va_loc_list) {
foreach ($va_loc_list as $va_loc) {
MediaContentLocationIndexer::index($vn_rep_table_num, $vn_rep_id, $vs_content, $va_loc['p'], $va_loc['x1'], $va_loc['y1'], $va_loc['x2'], $va_loc['y2']);
}
}
MediaContentLocationIndexer::write();
} else {
//CLIUtils::addError(_t("[Warning] No content to reindex for PDF representation: %1", $vs_path));
}
}
print CLIProgressBar::finish();
}
if (in_array('all', $va_kinds) || in_array('ca_attributes', $va_kinds)) {
// get all Media elements
$va_elements = ca_metadata_elements::getElementsAsList(false, null, null, true, false, true, array(16));
// 16=media
$qr_c = $o_db->query("\n\t\t\t\t\tSELECT count(*) c \n\t\t\t\t\tFROM ca_attribute_values\n\t\t\t\t\tWHERE\n\t\t\t\t\t\telement_id in (?)\n\t\t\t\t", caExtractValuesFromArrayList($va_elements, 'element_id', array('preserveKeys' => false)));
if ($qr_c->nextRow()) {
$vn_count = $qr_c->get('c');
} else {
$vn_count = 0;
}
$t_attr_val = new ca_attribute_values();
$vn_attr_table_num = $t_attr_val->tableNum();
print CLIProgressBar::start($vn_count, _t('Reindexing metadata attribute media'));
foreach ($va_elements as $vs_element_code => $va_element_info) {
$qr_vals = $o_db->query("SELECT value_id FROM ca_attribute_values WHERE element_id = ?", (int) $va_element_info['element_id']);
//.........这里部分代码省略.........
示例3: saveBundlesForScreen
/**
* Saves all bundles on the specified screen in the database by extracting
* required data from the supplied request
* $pm_screen can be a screen tag (eg. "Screen5") or a screen_id (eg. 5)
*
* Calls processBundlesBeforeBaseModelSave() method in subclass right before invoking insert() or update() on
* the BaseModel, if the method is defined. Passes the following parameters to processBundlesBeforeBaseModelSave():
* array $pa_bundles An array of bundles to be saved
* string $ps_form_prefix The form prefix
* RequestHTTP $po_request The current request
* array $pa_options Optional array of parameters; expected to be the same as that passed to saveBundlesForScreen()
*
* The processBundlesBeforeBaseModelSave() is useful for those odd cases where you need to do some processing before the basic
* database record defined by the model (eg. intrinsic fields and hierarchy coding) is inserted or updated. You usually don't need
* to use it.
*
* @param mixed $pm_screen
* @param RequestHTTP $ps_request
* @param array $pa_options Options are:
* dryRun = Go through the motions of saving but don't actually write information to the database
* batch = Process save in "batch" mode. Specifically this means honoring batch mode settings (add, replace, remove), skipping bundles that are not supported in batch mode and ignoring updates
* existingRepresentationMap = an array of representation_ids key'ed on file path. If set saveBundlesForScreen() use link the specified representation to the row it is saving rather than processing the uploaded file. saveBundlesForScreen() will build the map as it goes, adding newly uploaded files. If you want it to process a file in a batch situation where it should be processed the first time and linked subsequently then pass an empty array here. saveBundlesForScreen() will use the empty array to build the map.
*/
public function saveBundlesForScreen($pm_screen, $po_request, &$pa_options)
{
$vb_we_set_transaction = false;
$vs_form_prefix = caGetOption('formName', $pa_options, $po_request->getParameter('_formName', pString));
$vb_dryrun = caGetOption('dryRun', $pa_options, false);
$vb_batch = caGetOption('batch', $pa_options, false);
if (!$this->inTransaction()) {
$this->setTransaction(new Transaction($this->getDb()));
$vb_we_set_transaction = true;
} else {
if ($vb_dryrun) {
$this->postError(799, _t('Cannot do dry run save when in transaction. Try again without setting a transaction.'), "BundlableLabelableBaseModelWithAttributes->saveBundlesForScreen()");
return false;
}
}
$vb_read_only_because_deaccessioned = $this->hasField('is_deaccessioned') && (bool) $this->getAppConfig()->get('deaccession_dont_allow_editing') && (bool) $this->get('is_deaccessioned');
BaseModel::setChangeLogUnitID();
// get items on screen
$t_ui = caGetOption('ui_instance', $pa_options, ca_editor_uis::loadDefaultUI($this->tableName(), $po_request, $this->getTypeID()));
$va_bundle_lists = $this->getBundleListsForScreen($pm_screen, $po_request, $t_ui, $pa_options);
//
// Filter bundles to save if deaccessioned - only allow editing of the ca_objects_deaccession bundle
//
if ($vb_read_only_because_deaccessioned) {
foreach ($va_bundle_lists['bundles'] as $vn_i => $va_bundle) {
if ($va_bundle['bundle_name'] !== 'ca_objects_deaccession') {
unset($va_bundle_lists['bundles'][$vn_i]);
}
}
foreach ($va_bundle_lists['fields_by_type'] as $vs_type => $va_bundles) {
foreach ($va_bundles as $vs_id => $vs_bundle_name) {
if ($vs_bundle_name !== 'ca_objects_deaccession') {
unset($va_bundle_lists['fields_by_type'][$vs_type][$vs_id]);
}
}
}
}
$va_bundles = $va_bundle_lists['bundles'];
$va_fields_by_type = $va_bundle_lists['fields_by_type'];
// save intrinsic fields
if (is_array($va_fields_by_type['intrinsic'])) {
$vs_idno_field = $this->getProperty('ID_NUMBERING_ID_FIELD');
foreach ($va_fields_by_type['intrinsic'] as $vs_placement_code => $vs_f) {
if ($vb_batch) {
$vs_batch_mode = $po_request->getParameter("{$vs_placement_code}{$vs_form_prefix}_batch_mode", pString);
if ($vs_batch_mode == '_disabled_') {
continue;
}
}
if (isset($_FILES["{$vs_placement_code}{$vs_form_prefix}{$vs_f}"]) && $_FILES["{$vs_placement_code}{$vs_form_prefix}{$vs_f}"]) {
// media field
$this->set($vs_f, $_FILES["{$vs_placement_code}{$vs_form_prefix}{$vs_f}"]['tmp_name'], array('original_filename' => $_FILES["{$vs_placement_code}{$vs_form_prefix}{$vs_f}"]['name']));
} else {
switch ($vs_f) {
case 'access':
if ((bool) $this->getAppConfig()->get($this->tableName() . '_allow_access_inheritance') && $this->hasField('access_inherit_from_parent')) {
$this->set('access_inherit_from_parent', $po_request->getParameter("{$vs_placement_code}{$vs_form_prefix}access_inherit_from_parent", pInteger));
}
if (!(bool) $this->getAppConfig()->get($this->tableName() . '_allow_access_inheritance') || !$this->hasField('access_inherit_from_parent') || !(bool) $this->get('access_inherit_from_parent')) {
$this->set('access', $po_request->getParameter("{$vs_placement_code}{$vs_form_prefix}access", pString));
}
break;
case $vs_idno_field:
if ($this->opo_idno_plugin_instance) {
$this->opo_idno_plugin_instance->setDb($this->getDb());
$this->set($vs_f, $vs_tmp = $this->opo_idno_plugin_instance->htmlFormValue($vs_idno_field));
} else {
$this->set($vs_f, $po_request->getParameter("{$vs_placement_code}{$vs_form_prefix}{$vs_f}", pString));
}
break;
default:
// Look for fully qualified intrinsic
if (!strlen($vs_v = $po_request->getParameter("{$vs_placement_code}{$vs_form_prefix}{$vs_f}", pString))) {
// fall back to simple field name intrinsic spec - still used for "mandatory" fields such as type_id and parent_id
$vs_v = $po_request->getParameter("{$vs_f}", pString);
}
$this->set($vs_f, $vs_v);
//.........这里部分代码省略.........
示例4: update
/**
* Update annotation. If time code of annotation has changed media preview will be regenerated.
* You can force the media preview to be regenerated whether the time code has changed or not
* by passing the 'forcePreviewGeneration' option.
*
* @param array $pa_options An array of options:
* forcePreviewGeneration = if set preview media will be regenerated whether time code has changed or not. Default is false.
* @return bool True on success, false on failure
*/
public function update($pa_options = null)
{
$this->set('type_code', $vs_type = $this->getAnnotationType());
if (!$this->opo_annotations_properties->validate()) {
$this->errors = $this->opo_annotations_properties->errors;
return false;
}
$this->set('props', $this->opo_annotations_properties->getPropertyValues());
if (!$this->getAppConfig()->get('dont_generate_annotation_previews') && $this->getPrimaryKey() && ($this->changed('props') || isset($pa_options['forcePreviewGeneration']) && $pa_options['forcePreviewGeneration'])) {
$vs_start = $this->getPropertyValue('startTimecode');
$vs_end = $this->getPropertyValue('endTimecode');
$va_data['start'] = $vs_start;
$va_data['end'] = $vs_end;
$t_rep = new ca_object_representations($this->get('representation_id'));
if (($vs_file = $t_rep->getMediaPath('media', 'original')) && file_exists($vs_file)) {
$o_media = new Media();
if ($o_media->read($vs_file)) {
if ($o_media->writeClip($vs_file = tempnam(caGetTempDirPath(), 'annotationPreview'), $vs_start, $vs_end)) {
$this->set('preview', $vs_file);
}
}
}
}
$vn_rc = parent::update($pa_options);
if (!$this->numErrors()) {
$this->opo_annotations_properties = $this->loadProperties($vs_type);
}
if ($vs_file) {
@unlink($vs_file);
}
return $vn_rc;
}
示例5: render
function render($po_pdf, $pn_x = null, $pn_y = null)
{
switch (get_class($this->opo_form)) {
case 'PrintForms':
if ($va_element_info = $this->opa_element_info) {
$vn_x = $this->opo_form->getValueInPoints($va_element_info['left']);
$vn_y = $this->opo_form->getFormSetting('pageHeight') - $this->opo_form->getValueInPoints($va_element_info['top']);
}
break;
case 'PrintSubForms':
if ($va_element_info = $this->opa_element_info) {
$vn_x = $pn_x + $this->opo_form->getValueInPoints($va_element_info['left']);
$vn_y = $pn_y - $this->opo_form->getValueInPoints($va_element_info['top']);
}
break;
default:
$this->opo_form->postError(2275, _t("Invalid class '%1'", get_class($this->opo_form)), "PrintFormImageElement->render()");
break;
}
$va_style = $this->opo_form->getStyle($va_element_info['style']);
$vn_w = $this->opo_form->getValueInPoints($va_element_info['width']);
$vn_h = $this->opo_form->getValueInPoints($va_element_info['height']);
if ($this->opo_form->getPDFLibrary() == __PDF_LIBRARY_ZEND__) {
$o_media = new Media();
if ($o_media->read($this->getValue())) {
$va_properties = $o_media->getProperties();
$vn_image_width = $va_properties['width'];
$vn_image_height = $va_properties['height'];
if ($vn_image_width > $vn_image_height) {
$vn_r = $vn_w / $vn_image_width;
} else {
$vn_r = $vn_h / $vn_image_height;
}
$vn_image_width *= $vn_r;
$vn_image_height *= $vn_r;
$po_page = $po_pdf->pages[sizeof($po_pdf->pages) - 1];
try {
if ($vo_image = $this->opo_form->loadImage($po_pdf, $this->getValue())) {
$po_page->drawImage($vo_image, $vn_x, $vn_y - $vn_h, $vn_x + $vn_image_width, $vn_y - $vn_h + $vn_image_height);
} else {
return false;
}
} catch (Exception $e) {
return false;
}
}
} else {
if ($vn_image_ref = $this->opo_form->loadImage($po_pdf, $this->getValue())) {
if (!($vs_display = $va_element_info['display'])) {
$vs_display = $va_style['display'];
}
if (!in_array($vs_display, array('nofit', 'clip', 'meet', 'auto', 'slice', 'entire'))) {
$vs_display = 'meet';
}
$vs_opts = "fitmethod={$vs_display} boxsize={" . $vn_w . " " . $vn_h . "}";
if ($va_element_info['rotate']) {
$vs_opts .= ' rotate=' . intval($va_element_info['rotate']);
} else {
if ($va_style['rotate']) {
$vs_opts .= ' rotate=' . intval($va_style['rotate']);
}
}
$po_pdf->fit_image($vn_image_ref, $vn_x, $vn_y - $vn_h, $vs_opts);
}
}
return true;
}
示例6: 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;
}
示例7: 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");
//.........这里部分代码省略.........
示例8: 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;
//.........这里部分代码省略.........
示例9: Media
/**
*
*/
public function &writePreviews($ps_filepath, $pa_options)
{
if ($vs_pdf_path = WLPlugMediaOffice::$s_pdf_conv_cache[$this->filepath]) {
$o_media = new Media();
if ($o_media->read($vs_pdf_path)) {
return $o_media->writePreviews(array_merge($pa_options, array('dontUseDefaultIcons' => true)));
}
}
return null;
}
示例10: getClip
/**
*
*/
public function getClip()
{
$pn_id = $this->opo_request->getParameter('id', pInteger);
$va_data = array();
$t_annotation = new ca_representation_annotations($pn_id);
if ($t_annotation->getPrimaryKey()) {
$vs_start = $t_annotation->getPropertyValue('startTimecode');
$vs_end = $t_annotation->getPropertyValue('endTimecode');
$va_data['start'] = $vs_start;
$va_data['end'] = $vs_end;
$t_rep = new ca_object_representations($t_annotation->get('representation_id'));
$va_data['file'] = $vs_file = $t_rep->getMediaPath('media', 'original');
$o_media = new Media();
if ($o_media->read($vs_file)) {
$o_media->writeClip($vs_file = tempnam('/tmp', 'meow'), $vs_start, $vs_end);
}
header("Content-type: audio/mpeg");
header("Content-length: " . @filesize($vs_file));
readfile($vs_file);
return;
}
return $this->makeResponse($va_data, 500, "No such clip");
}