本文整理汇总了PHP中caEscapeShellArg函数的典型用法代码示例。如果您正苦于以下问题:PHP caEscapeShellArg函数的具体用法?PHP caEscapeShellArg怎么用?PHP caEscapeShellArg使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了caEscapeShellArg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _CoreImageRead
private function _CoreImageRead($ps_filepath)
{
if (caMediaPluginCoreImageInstalled($this->ops_CoreImage_path)) {
$vs_output = shell_exec('sips --getProperty format --getProperty space --getProperty bitsPerSample --getProperty pixelWidth --getProperty pixelHeight --getProperty dpiWidth --getProperty dpiHeight ' . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""));
$va_tmp = explode("\n", $vs_output);
array_shift($va_tmp);
$va_properties = array();
foreach ($va_tmp as $vs_line) {
$va_line_tmp = explode(':', $vs_line);
$va_properties[trim($va_line_tmp[0])] = trim($va_line_tmp[1]);
}
return array('mimetype' => $this->appleTypeToMimeType($va_properties['format']), 'magick' => $va_properties['format'], 'width' => $va_properties['pixelWidth'], 'height' => $va_properties['pixelHeight'], 'ops' => array(), 'filepath' => $ps_filepath);
}
return null;
}
示例2: render
/**
* Render HTML formatted string as a PDF
*
* @param string $ps_content A fully-formed HTML document to render as a PDF
* @param array $pa_options Options include:
* stream = Output the rendered PDF directly to the response [Default=false]
* filename = The filename to set the PDF to when streams [Default=export_results.pdf]
*
* @return string The rendered PDF content
* @seealso WLPlugPDFRendererPhantomJS::renderFile()
*/
public function render($ps_content, $pa_options = null)
{
file_put_contents($vs_content_path = caMakeGetFilePath("phantomjs", "html"), $ps_content);
$vs_output_path = caMakeGetFilePath("phantomjs", "pdf");
exec($x = $this->ops_phantom_path . " " . __CA_LIB_DIR__ . "/core/Print/phantomjs/rasterise.js " . caEscapeShellArg($vs_content_path) . " " . caEscapeShellArg($vs_output_path) . " {$this->ops_page_size} {$this->ops_page_orientation} {$this->ops_margin_right} {$this->ops_margin_bottom} {$this->ops_margin_left}", $va_output, $vn_return);
$vs_pdf_content = file_get_contents($vs_output_path);
if (caGetOption('stream', $pa_options, false)) {
header("Cache-Control: private");
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=" . caGetOption('filename', $pa_options, 'output.pdf'));
print $vs_pdf_content;
}
@unlink($vs_content_path);
@unlink($vs_output_path);
return $vs_pdf_content;
}
示例3: _CoreImageWrite
private function _CoreImageWrite($pa_handle, $ps_filepath, $ps_mimetype, $pn_quality = null)
{
if (caMediaPluginCoreImageInstalled($this->ops_CoreImage_path)) {
$va_ops = array();
foreach ($pa_handle['ops'] as $va_op) {
switch ($va_op['op']) {
case 'annotation':
// TODO: annotation is not currrently supported in this plugin
//$vs_op = '-gravity '.$va_op['position'].' -fill '.str_replace('#', '\\#', $va_op['color']).' -pointsize '.$va_op['size'].' -draw "text '.$va_op['inset'].','.$va_op['inset'].' \''.$va_op['text'].'\'"';
//if ($va_op['font']) {
// $vs_op .= ' -font '.$va_op['font'];
//}
//$va_ops['convert'][] = $vs_op;
break;
case 'watermark':
// TODO: watermark position is not currently handled in this plugin
if (is_array($va_ops) && sizeof($va_ops)) {
array_unshift($va_ops, "load watermark " . caEscapeShellArg($va_op['watermark_image']));
}
$va_ops[] = "filter watermark CIStretchCrop size=" . $va_op['watermark_width'] . "," . $va_op['watermark_height'] . ":cropAmount=0:centerStretchAmount=0";
$va_ops[] = "filter watermark CIColorMatrix RVector=1,0,0,0:GVector=0,1,0,0:BVector=0,0,1,0:AVector=0,0,0," . $va_op['opacity'] . ":BiasVector=0,0,0,0";
$va_ops[] = "filter image CISoftLightBlendMode backgroundImage=watermark";
break;
case 'size':
if ($va_op['width'] < 1) {
break;
}
if ($va_op['height'] < 1) {
break;
}
$vn_scale = $va_op['width'] / $this->handle['width'];
$va_ops[] = "filter image CILanczosScaleTransform scale={$vn_scale}:aspectRatio=1";
break;
case 'crop':
if ($va_op['width'] < 1) {
break;
}
if ($va_op['height'] < 1) {
break;
}
if ($va_op['x'] < 0) {
break;
}
if ($va_op['y'] < 0) {
break;
}
$va_ops[] = "filter image CICrop rectangle=" . join(",", array($va_op['x'], $va_op['y'], $va_op['width'], $va_op['height']));
break;
case 'rotate':
if (!is_numeric($va_op['angle'])) {
break;
}
$va_ops[] = "filter image CIAffineTransform transform=" . cos($va_op['angle']) . "," . -1 * sin($va_op['angle']) . ",0," . sin($va_op['angle']) . "," . cos($va_op['angle']) . ",0";
break;
case 'filter_despeckle':
// TODO: see if this works nicely... just using default values
$va_ops[] = "filter image CINoiseReduction inputNoiseLevel=0.2:inputSharpness=0.4";
break;
case 'filter_median':
if ($va_op['radius'] < 0) {
break;
}
// NOTE: CoreImage Median doesn't take a radius, unlike ImageMagick's
$va_ops[] = "filter image CIMedianFilter ";
break;
case 'filter_unsharp_mask':
case 'filter_sharpen':
if ($va_op['radius'] < 0) {
break;
}
$vn_radius = $va_op['radius'];
if (!($vn_intensity = $va_op['amount'])) {
$vn_intensity = 1;
}
$va_ops[] = "filter image CIUnsharpMask radius={$vn_radius}:intensity={$vn_intensity}";
break;
}
}
if (isset($this->properties["orientation_rotate"]) && $this->properties["orientation_rotate"] != 0) {
$va_ops[] = "filter image CIAffineTransform transform=" . cos($va_op['angle']) . "," . -1 * sin($this->properties["orientation_rotate"]) . ",0," . sin($this->properties["orientation_rotate"]) . "," . cos($this->properties["orientation_rotate"]) . ",0";
}
$vs_input_file = $pa_handle['filepath'];
if (is_array($va_ops) && sizeof($va_ops)) {
array_unshift($va_ops, "load image " . caEscapeShellArg($vs_input_file));
array_push($va_ops, "store image " . caEscapeShellArg($ps_filepath) . " " . $this->apple_UTIs[$ps_mimetype]);
//print "<hr>".join(" ", $va_ops)."<hr>";
exec($this->ops_CoreImage_path . " " . join(" ", $va_ops));
$vs_input_file = $ps_filepath;
}
return true;
}
return null;
}
示例4: TimecodeParser
public function &writePreviews($ps_filepath, $pa_options)
{
if (!(bool) $this->opo_config->get("video_preview_generate_frames")) {
return false;
}
if (!isset($pa_options['outputDirectory']) || !$pa_options['outputDirectory'] || !file_exists($pa_options['outputDirectory'])) {
if (!($vs_tmp_dir = $this->opo_config->get("taskqueue_tmp_directory"))) {
// no dir
return false;
}
} else {
$vs_tmp_dir = $pa_options['outputDirectory'];
}
$o_tc = new TimecodeParser();
if (($vn_min_number_of_frames = $pa_options['minNumberOfFrames']) < 1) {
$vn_min_number_of_frames = 0;
}
if (($vn_max_number_of_frames = $pa_options['maxNumberOfFrames']) < 1) {
$vn_max_number_of_frames = 100;
}
$vn_duration = $this->properties["duration"];
if (!($vn_frame_interval = $o_tc->parse($pa_options['frameInterval']) ? $o_tc->getSeconds() : 0)) {
$vn_frame_interval = 30;
}
if (!($vn_start_at = $o_tc->parse($pa_options['startAtTime']) ? $o_tc->getSeconds() : 0)) {
$vn_start_at = 0;
}
if (!($vn_end_at = $o_tc->parse($pa_options['endAtTime']) ? $o_tc->getSeconds() : 0)) {
$vn_end_at = 0;
}
if (($vn_previewed_duration = $vn_duration - $vn_start_at - $vn_end_at) < 0) {
$vn_previewed_duration = $vn_duration;
$vn_start_at = $vn_end_at = 0;
}
if ($vn_frame_interval > $vn_previewed_duration) {
$vn_frame_interval = $vn_previewed_duration;
}
$vn_preview_width = isset($pa_options['width']) && (int) $pa_options['width'] > 0 ? (int) $pa_options['width'] : 320;
$vn_preview_height = isset($pa_options['height']) && (int) $pa_options['height'] > 0 ? (int) $pa_options['height'] : 320;
$vn_s = $vn_start_at;
$vn_e = $vn_duration - $vn_end_at;
$vn_num_frames = $vn_previewed_duration / $vn_frame_interval;
if ($vn_num_frames < $vn_min_number_of_frames) {
$vn_frame_interval = $vn_previewed_duration / $vn_min_number_of_frames;
$vn_num_frames = $vn_min_number_of_frames;
$vn_previewed_duration = $vn_num_frames * $vn_frame_interval;
}
if ($vn_num_frames > $vn_max_number_of_frames) {
$vn_frame_interval = $vn_previewed_duration / $vn_max_number_of_frames;
$vn_num_frames = $vn_max_number_of_frames;
$vn_previewed_duration = $vn_num_frames * $vn_frame_interval;
}
$vs_freq = 1 / $vn_frame_interval;
$vs_output_file_prefix = tempnam($vs_tmp_dir, 'caQuicktimeVRPreview');
$vs_output_file = $vs_output_file_prefix . '%05d.jpg';
exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f image2 -r " . $vs_freq . " -ss {$vn_s} -t {$vn_previewed_duration} -s " . $vn_preview_width . "x" . $vn_preview_height . " -y " . caEscapeShellArg($vs_output_file), $va_output, $vn_return);
$vn_i = 1;
$va_files = array();
while (file_exists($vs_output_file_prefix . sprintf("%05d", $vn_i) . '.jpg')) {
// add frame to list
$va_files['' . sprintf("%4.2f", ($vn_i - 1) * $vn_frame_interval + $vn_s) . 's'] = $vs_output_file_prefix . sprintf("%05d", $vn_i) . '.jpg';
$vn_i++;
}
if (!sizeof($va_files)) {
$this->postError(1610, _t("Couldn't not write video preview frames to tmp directory (%1)", $vs_tmp_dir), "WLPlugQuicktimeVR->write()");
}
@unlink($vs_output_file_prefix);
return $va_files;
}
示例5: read
public function read($ps_filepath, $mimetype = "")
{
if (!($this->handle && ${$ps_filepath} === $this->filepath)) {
if ($mimetype == 'image/tilepic') {
#
# Read in Tilepic format image
#
$this->handle = new TilepicParser($ps_filepath);
if (!$this->handle->error) {
$this->filepath = $ps_filepath;
foreach ($this->handle->properties as $k => $v) {
if (isset($this->properties[$k])) {
$this->properties[$k] = $v;
}
}
$this->properties["mimetype"] = "image/tilepic";
$this->properties["typename"] = "Tilepic";
return 1;
} else {
$this->postError(1610, $this->handle->error, "WLPlugImagick->read()");
return false;
}
} else {
$this->handle = "";
$this->filepath = "";
$handle = new Imagick();
if ($mimetype == 'image/x-dcraw') {
if ($this->filepath_conv) {
@unlink($this->filepath_conv);
}
if (!caMediaPluginDcrawInstalled($this->ops_dcraw_path)) {
$this->postError(1610, _t("Could not convert Camera RAW format file because conversion tool (dcraw) is not installed"), "WLPlugImagick->read()");
return false;
}
$vs_tmp_name = tempnam(caGetTempDirPath(), "rawtmp");
if (!copy($ps_filepath, $vs_tmp_name)) {
$this->postError(1610, _t("Could not copy Camera RAW file to temporary directory"), "WLPlugImagick->read()");
return false;
}
exec($this->ops_dcraw_path . " -T " . caEscapeShellArg($vs_tmp_name), $va_output, $vn_return);
if ($vn_return != 0) {
$this->postError(1610, _t("Camera RAW file conversion failed: %1", $vn_return), "WLPlugImagick->read()");
return false;
}
if (!(file_exists($vs_tmp_name . '.tiff') && filesize($vs_tmp_name . '.tiff') > 0)) {
$this->postError(1610, _t("Translation from Camera RAW to TIFF failed"), "WLPlugImagick->read()");
return false;
}
$ps_filepath = $this->filepath_conv = $vs_tmp_name . '.tiff';
@unlink($vs_tmp_name);
}
if ($handle->readImage($ps_filepath)) {
$this->handle = $handle;
$this->filepath = $ps_filepath;
$va_raw_metadata = $this->handle->getImageProperties();
$this->metadata = array();
foreach ($va_raw_metadata as $vs_tag => $vs_value) {
if (sizeof($va_tmp = explode(':', $vs_tag)) > 1) {
$vs_type = strtoupper($va_tmp[0]);
$vs_tag = $va_tmp[1];
} else {
$vs_type = 'GENERIC';
}
if ($vs_type == 'EXIF') {
continue;
}
$this->metadata[$vs_type][$vs_tag] = $vs_value;
}
// exif
if (function_exists('exif_read_data')) {
if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
//
// Rotate incoming image as needed
//
if (isset($va_exif['IFD0']['Orientation'])) {
$vn_orientation = $va_exif['IFD0']['Orientation'];
$vs_tmp_basename = tempnam(caGetTempDirPath(), 'ca_image_tmp');
$vb_is_rotated = false;
switch ($vn_orientation) {
case 3:
$this->handle->rotateImage("#FFFFFF", 180);
unset($va_exif['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
case 6:
$this->handle->rotateImage("#FFFFFF", 90);
unset($va_exif['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
case 8:
$this->handle->rotateImage("#FFFFFF", -90);
unset($va_exif['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
}
if ($vb_is_rotated) {
if ($this->handle->writeImage($vs_tmp_basename)) {
$va_tmp = $this->handle->getImageGeometry();
$this->properties["faces"] = $this->opa_faces = caDetectFaces($vs_tmp_basename, $va_tmp['width'], $va_tmp['height']);
}
//.........这里部分代码省略.........
示例6: _gmagickRead
private function _gmagickRead($ps_filepath)
{
try {
$handle = new Gmagick($ps_filepath);
$this->setResourceLimits($handle);
$handle->setimageindex(0);
// force use of first image in multi-page TIFF
$this->handle = $handle;
$this->filepath = $ps_filepath;
$this->metadata = array();
// handle metadata
/* EXIF */
if (function_exists('exif_read_data') && !$this->opo_config->get('dont_use_exif_read_data')) {
if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
$va_metadata['EXIF'] = $va_exif;
}
}
// if the builtin EXIF extraction is not used or failed for some reason, try ExifTool
if (!isset($va_metadata['EXIF']) || !is_array($va_metadata['EXIF'])) {
if (caExifToolInstalled()) {
$va_metadata['EXIF'] = caExtractMetadataWithExifTool($ps_filepath, true);
}
}
// Rotate incoming image as needed
if (isset($va_metadata['EXIF']['IFD0']['Orientation'])) {
$vn_orientation = $va_metadata['EXIF']['IFD0']['Orientation'];
$vs_tmp_basename = tempnam(caGetTempDirPath(), 'ca_image_tmp');
$vb_is_rotated = false;
switch ($vn_orientation) {
case 3:
$this->handle->rotateimage("#FFFFFF", 180);
unset($va_metadata['EXIF']['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
case 6:
$this->handle->rotateimage("#FFFFFF", 90);
unset($va_metadata['EXIF']['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
case 8:
$this->handle->rotateimage("#FFFFFF", -90);
unset($va_metadata['EXIF']['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
}
if ($vb_is_rotated) {
if ($this->handle->writeimage($vs_tmp_basename)) {
$va_tmp = $this->handle->getimagegeometry();
$this->properties["faces"] = $this->opa_faces = caDetectFaces($vs_tmp_basename, $va_tmp['width'], $va_tmp['height']);
}
@unlink($vs_tmp_basename);
}
}
// get XMP
$o_xmp = new XMPParser();
if ($o_xmp->parse($ps_filepath)) {
if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
$va_metadata['XMP'] = array();
foreach ($va_xmp_metadata as $vs_xmp_tag => $va_xmp_values) {
$va_metadata['XMP'][$vs_xmp_tag] = join('; ', $va_xmp_values);
}
}
}
// try to get IPTC and DPX with GraphicsMagick, if available
if (caMediaPluginGraphicsMagickInstalled()) {
/* IPTC metadata */
$vs_iptc_file = tempnam(caGetTempDirPath(), 'gmiptc');
@rename($vs_iptc_file, $vs_iptc_file . '.iptc');
// GM uses the file extension to figure out what we want
$vs_iptc_file .= '.iptc';
exec($this->ops_graphicsmagick_path . " convert " . caEscapeShellArg($ps_filepath) . " " . caEscapeShellArg($vs_iptc_file) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
$vs_iptc_data = file_get_contents($vs_iptc_file);
@unlink($vs_iptc_file);
$va_iptc_raw = iptcparse($vs_iptc_data);
$va_iptc_tags = array('2#004' => 'Genre', '2#005' => 'DocumentTitle', '2#010' => 'Urgency', '2#015' => 'Category', '2#020' => 'Subcategories', '2#025' => 'Keywords', '2#040' => 'SpecialInstructions', '2#055' => 'CreationDate', '2#060' => 'TimeCreated', '2#080' => 'AuthorByline', '2#085' => 'AuthorTitle', '2#090' => 'City', '2#095' => 'State', '2#100' => 'CountryCode', '2#101' => 'Country', '2#103' => 'OTR', '2#105' => 'Headline', '2#110' => 'Credit', '2#115' => 'PhotoSource', '2#116' => 'Copyright', '2#120' => 'Caption', '2#122' => 'CaptionWriter');
$va_iptc = array();
if (is_array($va_iptc_raw)) {
foreach ($va_iptc_raw as $vs_iptc_tag => $va_iptc_tag_data) {
if (isset($va_iptc_tags[$vs_iptc_tag])) {
$va_iptc[$va_iptc_tags[$vs_iptc_tag]] = join('; ', $va_iptc_tag_data);
}
}
}
if (sizeof($va_iptc)) {
$va_metadata['IPTC'] = $va_iptc;
}
/* DPX metadata */
exec($this->ops_graphicsmagick_path . " identify -format '%[DPX:*]' " . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
if ($va_output[0]) {
$va_metadata['DPX'] = $va_output;
}
}
$this->metadata = $va_metadata;
return $handle;
} catch (Exception $e) {
$this->postError(1610, _t("Could not read image file"), "WLPlugGmagick->read()");
return false;
// gmagick couldn't read file, presumably
}
}
示例7: _graphicsMagickProcess
private function _graphicsMagickProcess($ps_source_filepath, $ps_dest_filepath, $pa_ops, $pn_quality = null)
{
$va_ops = array('-colorspace RGB');
if (!is_null($pn_quality)) {
$va_ops[] = '-quality ' . intval($pn_quality);
}
foreach ($pa_ops as $va_op) {
switch ($va_op['op']) {
case 'size':
if ($va_op['width'] < 1) {
break;
}
if ($va_op['height'] < 1) {
break;
}
$va_ops[] = '-resize ' . $va_op['width'] . 'x' . $va_op['height'] . ' -filter Cubic';
break;
case 'crop':
if ($va_op['width'] < 1) {
break;
}
if ($va_op['height'] < 1) {
break;
}
if ($va_op['x'] < 0) {
break;
}
if ($va_op['y'] < 0) {
break;
}
$va_ops[] = '-crop ' . $va_op['width'] . 'x' . $va_op['height'] . '+' . $va_op['x'] . '+' . $va_op['y'];
break;
case 'rotate':
if (!is_numeric($va_op['angle'])) {
break;
}
$va_ops[] = '-rotate ' . $va_op['angle'];
break;
case 'filter_despeckle':
$va_ops[] = '-despeckle';
break;
case 'filter_sharpen':
if ($va_op['radius'] < 0) {
break;
}
$vs_tmp = '-sharpen ' . $va_op['radius'];
if (isset($va_op['sigma'])) {
$vs_tmp .= 'x' . $va_op['sigma'];
}
$va_ops[] = $vs_tmp;
break;
case 'filter_median':
if ($va_op['radius'] < 0) {
break;
}
$va_ops[] = '-median ' . $va_op['radius'];
break;
case 'filter_unsharp_mask':
if ($va_op['radius'] < 0) {
break;
}
$vs_tmp = '-unsharp ' . $va_op['radius'];
if (isset($va_op['sigma'])) {
$vs_tmp .= 'x' . $va_op['sigma'];
}
if (isset($va_op['amount'])) {
$vs_tmp .= '+' . $va_op['amount'];
}
if (isset($va_op['threshold'])) {
$vs_tmp .= '+' . $va_op['threshold'];
}
$va_ops[] = $vs_tmp;
break;
case 'strip':
// option
//$va_ops[] = '-strip';
$va_ops[] = '+profile "*"';
break;
}
}
exec($this->ops_graphicsmagick_path . ' convert ' . caEscapeShellArg($ps_source_filepath . '[0]') . ' ' . join(' ', $va_ops) . ' "' . $ps_dest_filepath . '"');
return true;
}
示例8: 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");
//.........这里部分代码省略.........
示例9: writeClip
/**
*
*/
public function writeClip($ps_filepath, $ps_start, $ps_end, $pa_options = null)
{
if (!caMediaPluginFFmpegInstalled()) {
return false;
}
$o_tc = new TimecodeParser();
$vn_start = $vn_end = null;
if ($o_tc->parse($ps_start)) {
$vn_start = $o_tc->getSeconds();
}
if ($o_tc->parse($ps_end)) {
$vn_end = $o_tc->getSeconds();
}
if (!$vn_start || !$vn_end) {
return null;
}
if ($vn_start >= $vn_end) {
return null;
}
$vn_duration = $vn_end - $vn_start;
exec(caGetExternalApplicationPath('ffmpeg') . " -i " . caEscapeShellArg($this->filepath) . " -f mp4 -vcodec libx264 -acodec mp3 -t {$vn_duration} -y -ss {$vn_start} " . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
if ($vn_return != 0) {
@unlink($ps_filepath);
$this->postError(1610, _t("Error extracting clip from %1 to %2: %3", $ps_start, $ps_end, join("; ", $va_output)), "WLPlugVideo->writeClip()");
return false;
}
return true;
}
示例10: caEmbedMediaMetadataIntoFile
/**
* Embed media metadata into given file. Embedding is performed on a copy of the file and placed into the
* system tmp directory. The given file is never modified.
*
* @param string $ps_file The file to embed metadata into
* @param string $ps_table Table name of the subject record. This is used to figure out the appropriate mapping to use from media_metadata.conf
* @param int $pn_pk Primary key of the subject record. This is used to run the export for the right record.
* @param string $ps_type_code Optional type code for the subject record
* @param int $pn_rep_pk Primary key of the subject representation.
* If there are export mapping for object representations, we run them after the mapping for the subject table.
* Fields that get exported here should overwrite fields from the subject table export.
* @param string $ps_rep_type_code type code for object representation
* @return string File name of a temporary file with the embedded metadata, false on failure
*/
function caEmbedMediaMetadataIntoFile($ps_file, $ps_table, $pn_pk, $ps_type_code, $pn_rep_pk, $ps_rep_type_code)
{
require_once __CA_MODELS_DIR__ . '/ca_data_exporters.php';
if (!caExifToolInstalled()) {
return false;
}
// we need exiftool for embedding
$vs_path_to_exif_tool = caGetExternalApplicationPath('exiftool');
if (!file_exists($ps_file)) {
return false;
}
if (!preg_match("/^image\\//", mime_content_type($ps_file))) {
return false;
}
// Don't try to embed in files other than images
// make a temporary copy (we won't touch the original)
copy($ps_file, $vs_tmp_filepath = caGetTempDirPath() . "/" . time() . md5($ps_file));
//
// SUBJECT TABLE
//
if ($vs_subject_table_export = caExportMediaMetadataForRecord($ps_table, $ps_type_code, $pn_pk)) {
$vs_export_filename = caGetTempFileName('mediaMetadataSubjExport', 'xml');
if (@file_put_contents($vs_export_filename, $vs_subject_table_export) === false) {
return false;
}
exec("{$vs_path_to_exif_tool} -tagsfromfile {$vs_export_filename} -all:all " . caEscapeShellArg($vs_tmp_filepath), $va_output, $vn_return);
@unlink($vs_export_filename);
@unlink("{$vs_tmp_filepath}_original");
}
//
// REPRESENTATION
//
if ($vs_representation_Export = caExportMediaMetadataForRecord('ca_object_representations', $ps_rep_type_code, $pn_rep_pk)) {
$vs_export_filename = caGetTempFileName('mediaMetadataRepExport', 'xml');
if (@file_put_contents($vs_export_filename, $vs_representation_Export) === false) {
return false;
}
exec("{$vs_path_to_exif_tool} -tagsfromfile {$vs_export_filename} -all:all " . caEscapeShellArg($vs_tmp_filepath), $va_output, $vn_return);
@unlink($vs_export_filename);
@unlink("{$vs_tmp_filepath}_original");
}
return $vs_tmp_filepath;
}
示例11: render
/**
* Render HTML formatted string as a PDF
*
* @param string $ps_content A fully-formed HTML document to render as a PDF
* @param array $pa_options Options include:
* stream = Output the rendered PDF directly to the response [Default=false]
* filename = The filename to set the PDF to when streams [Default=output.pdf]
*
* @return string The rendered PDF content
* @seealso wkhtmltopdf::renderFile()
*/
public function render($ps_content, $pa_options = null)
{
// Extract header and footer
$vs_header = preg_match("/<!--BEGIN HEADER-->(.*)<!--END HEADER-->/s", $ps_content, $va_matches) ? $va_matches[1] : '';
$vs_footer = preg_match("/<!--BEGIN FOOTER-->(.*)<!--END FOOTER-->/s", $ps_content, $va_matches) ? $va_matches[1] : '';
$ps_content = preg_replace("/<!--BEGIN HEADER-->(.*)<!--END HEADER-->/s", "", $ps_content);
$ps_content = preg_replace("/<!--BEGIN FOOTER-->(.*)<!--END FOOTER-->/s", "", $ps_content);
file_put_contents($vs_content_path = caMakeGetFilePath("wkhtmltopdf", "html"), $ps_content);
file_put_contents($vs_header_path = caMakeGetFilePath("wkhtmltopdf", "html"), $vs_header);
file_put_contents($vs_footer_path = caMakeGetFilePath("wkhtmltopdf", "html"), $vs_footer);
$vs_output_path = caMakeGetFilePath("wkhtmltopdf", "pdf");
exec($this->ops_wkhtmltopdf_path . " --disable-smart-shrinking --dpi 96 --encoding UTF-8 --margin-top {$this->ops_margin_top} --margin-bottom {$this->ops_margin_bottom} --margin-left {$this->ops_margin_left} --margin-right {$this->ops_margin_right} --page-size {$this->ops_page_size} --orientation {$this->ops_page_orientation} page " . caEscapeShellArg($vs_content_path) . " --header-html {$vs_header_path} --footer-html {$vs_footer_path} {$vs_output_path}", $va_output, $vn_return);
$vs_pdf_content = file_get_contents($vs_output_path);
if (caGetOption('stream', $pa_options, false)) {
header("Cache-Control: private");
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=" . caGetOption('filename', $pa_options, 'output.pdf'));
print $vs_pdf_content;
}
@unlink($vs_content_path);
@unlink($vs_header_path);
@unlink($vs_footer_path);
@unlink($vs_output_path);
return $vs_pdf_content;
}
示例12: caExtractMetadataWithExifTool
/**
* Extracts media metadata using ExifTool
*
* @param string $ps_filepath file path
* @param string $ps_exiftool_path optional path to ExifTool binary. If omitted the path configured in external_applications.conf is used.
*
* @return array Extracted metadata
*/
function caExtractMetadataWithExifTool($ps_filepath, $ps_mediainfo_path = null)
{
if (caExifToolInstalled()) {
if (!$vs_path_to_exif_tool) {
$vs_path_to_exif_tool = caGetExternalApplicationPath('exiftool');
}
exec("{$vs_path_to_exif_tool} -json -a -u -g1 " . caEscapeShellArg($ps_filepath) . " 2> /dev/null", $va_output, $vn_return);
if (!is_array($va_data = array_pop(json_decode(join(" ", $va_output), true)))) {
return false;
}
return $va_data;
}
return null;
}
示例13: caExtractVideoFileDurationWithMediaInfo
/**
* Extract video duration using MediaInfo. This can be used as a fallback to getID3
* @param string $ps_filepath
*
* @return float|null
*/
function caExtractVideoFileDurationWithMediaInfo($ps_filepath)
{
$ps_mediainfo_path = caGetExternalApplicationPath('mediainfo');
if (!caMediaInfoInstalled($ps_mediainfo_path)) {
return false;
}
$va_output = array();
exec($ps_mediainfo_path . ' --Inform="Video;%Duration/String3%" ' . caEscapeShellArg($ps_filepath), $va_output, $vn_return);
if (!is_array($va_output) || sizeof($va_output) != 1) {
return null;
}
$va_tmp = explode(':', array_shift($va_output));
if (sizeof($va_tmp) == 3) {
// should have hours, minutes, seconds
return round(intval($va_tmp[0]) * 3600 + intval($va_tmp[1]) * 60 + floatval($va_tmp[2]));
}
return null;
}
示例14: 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;
}
示例15: _graphicsMagickWrite
//.........这里部分代码省略.........
//" -geometry ".$va_op['watermark_width']."x".$va_op['watermark_height']; [Seems to be interpreted as scaling the image being composited on as of at least v6.5.9; so we don't scale watermarks in ImageMagick... we just use the native size]
$va_ops['composite'][] = $vs_op;
break;
case 'size':
if ($va_op['width'] < 1) {
break;
}
if ($va_op['height'] < 1) {
break;
}
$va_ops['convert'][] = '-resize ' . $va_op['width'] . 'x' . $va_op['height'] . ' -filter Cubic';
break;
case 'crop':
if ($va_op['width'] < 1) {
break;
}
if ($va_op['height'] < 1) {
break;
}
if ($va_op['x'] < 0) {
break;
}
if ($va_op['y'] < 0) {
break;
}
$va_ops['convert'][] = '-crop ' . $va_op['width'] . 'x' . $va_op['height'] . '+' . $va_op['x'] . '+' . $va_op['y'];
break;
case 'rotate':
if (!is_numeric($va_op['angle'])) {
break;
}
$va_ops['convert'][] = '-rotate ' . $va_op['angle'];
break;
case 'filter_despeckle':
$va_ops['convert'][] = '-despeckle';
break;
case 'filter_sharpen':
if ($va_op['radius'] < 0) {
break;
}
$vs_tmp = '-sharpen ' . $va_op['radius'];
if (isset($va_op['sigma'])) {
$vs_tmp .= 'x' . $va_op['sigma'];
}
$va_ops['convert'][] = $vs_tmp;
break;
case 'filter_median':
if ($va_op['radius'] < 0) {
break;
}
$va_ops['convert'][] = '-median ' . $va_op['radius'];
break;
case 'filter_unsharp_mask':
if ($va_op['radius'] < 0) {
break;
}
$vs_tmp = '-unsharp ' . $va_op['radius'];
if (isset($va_op['sigma'])) {
$vs_tmp .= 'x' . $va_op['sigma'];
}
if (isset($va_op['amount'])) {
$vs_tmp .= '+' . $va_op['amount'];
}
if (isset($va_op['threshold'])) {
$vs_tmp .= '+' . $va_op['threshold'];
}
$va_ops['convert'][] = $vs_tmp;
break;
}
}
if (isset($this->properties["orientation_rotate"]) && $this->properties["orientation_rotate"] != 0) {
$va_ops['convert'][] = '-rotate ' . $this->properties["orientation_rotate"];
}
if ($this->properties['gamma']) {
if (!$this->properties['reference-black']) {
$this->properties['reference-black'] = 0;
}
if (!$this->properties['reference-white']) {
$this->properties['reference-white'] = 65535;
}
$va_ops['convert'][] = "-set gamma " . $this->properties['gamma'];
$va_ops['convert'][] = "-set reference-black " . $this->properties['reference-black'];
$va_ops['convert'][] = "-set reference-white " . $this->properties['reference-white'];
}
$vs_input_file = $pa_handle['filepath'];
if (is_array($va_ops['convert']) && sizeof($va_ops['convert'])) {
if (!is_null($pn_quality)) {
array_unshift($va_ops['convert'], '-quality ' . intval($pn_quality));
}
array_unshift($va_ops['convert'], '-colorspace RGB');
exec($this->ops_graphicsmagick_path . ' convert ' . caEscapeShellArg($vs_input_file . '[0]') . ' ' . join(' ', $va_ops['convert']) . ' ' . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""));
$vs_input_file = $ps_filepath;
}
if (is_array($va_ops['composite']) && sizeof($va_ops['composite'])) {
exec($this->ops_graphicsmagick_path . ' composite ' . join(' ', $va_ops['composite']) . ' ' . caEscapeShellArg($vs_input_file . '[0]') . ' ' . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""));
}
return true;
}
return null;
}