mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 20:43:25 +00:00
V 3.5 RC 1
This commit is contained in:
84
lib/classes/binaryAdapter/abstract.class.php
Normal file
84
lib/classes/binaryAdapter/abstract.class.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* General abstract object for binaryAdapter
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
abstract class binaryAdapter_abstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $debug = false;
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
*
|
||||
* @var registry
|
||||
*/
|
||||
protected $registry;
|
||||
|
||||
/**
|
||||
* Options setter
|
||||
*
|
||||
* @param array $options
|
||||
* @return binaryAdapter_abstract
|
||||
*/
|
||||
public function set_options($options)
|
||||
{
|
||||
foreach ($options as $option_name => $option_value)
|
||||
{
|
||||
$this->set_option($option_name, $option_value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Option setter
|
||||
*
|
||||
* @param array $name
|
||||
* @param array $value
|
||||
* @return binaryAdapter_abstract
|
||||
*/
|
||||
protected function set_option($name, $value)
|
||||
{
|
||||
$this->options[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*
|
||||
* @param <type> $message
|
||||
* @return binaryAdapter_abstract
|
||||
*/
|
||||
public function log($message)
|
||||
{
|
||||
if ($this->debug)
|
||||
{
|
||||
echo "\t --> \t" . $message . "\n";
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
80
lib/classes/binaryAdapter/adapterAbstract.class.php
Normal file
80
lib/classes/binaryAdapter/adapterAbstract.class.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abastract adapter object for binaryAdapter
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
abstract class binaryAdapter_adapterAbstract extends binaryAdapter_abstract implements binaryAdapter_adapterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param registry $registry
|
||||
* @return binaryAdapter_adapterAbstract
|
||||
*/
|
||||
public function __construct(registry $registry)
|
||||
{
|
||||
$this->registry = $registry;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @param array $options
|
||||
* @return system_file
|
||||
*/
|
||||
public function execute(system_file $origine, $dest, Array $options)
|
||||
{
|
||||
$processors = array();
|
||||
foreach ($this->processors as $k => $proc)
|
||||
{
|
||||
try
|
||||
{
|
||||
$processors[$k] = new $proc($this->registry);
|
||||
$this->log("" . $proc . " disponible");
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
unset($processors[$k]);
|
||||
$this->log($proc . " indisponible : " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$done = $resized = false;
|
||||
while (!$done && count($processors) > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
$proc = array_shift($processors);
|
||||
$resized = $proc->execute($origine, $dest, $options);
|
||||
$done = true;
|
||||
$this->log("effectuee ! ");
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->log($e->getMessage());
|
||||
}
|
||||
}
|
||||
if ($resized instanceof system_file)
|
||||
|
||||
return $resized;
|
||||
throw new Exception('None of the processor where able to perform ' . $this->get_name());
|
||||
}
|
||||
|
||||
abstract public function get_name();
|
||||
}
|
24
lib/classes/binaryAdapter/adapterInterface.class.php
Normal file
24
lib/classes/binaryAdapter/adapterInterface.class.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adapter interface for binaryAdapter
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
interface binaryAdapter_adapterInterface
|
||||
{
|
||||
public function __construct(registry $registry);
|
||||
|
||||
public function execute(system_file $origine, $dest, Array $options);
|
||||
}
|
34
lib/classes/binaryAdapter/audio/previewExtract.class.php
Normal file
34
lib/classes/binaryAdapter/audio/previewExtract.class.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_audio_previewExtract extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $processors = array(
|
||||
'binaryAdapter_audio_previewExtract_exiftool'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter audio image-preview extract';
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exiftool preview extractor from raw images processor
|
||||
* for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_audio_previewExtract_exiftool extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_exiftool';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $raw_datas
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $raw_datas, $dest)
|
||||
{
|
||||
$cmd = sprintf('%s -s -t %s'
|
||||
, $this->binary
|
||||
, $this->escapeshellargs($raw_datas->getPathname())
|
||||
);
|
||||
|
||||
$out = $this->shell_cmd($cmd);
|
||||
|
||||
if (!$out)
|
||||
throw new Exception('Unable to extract preview datas from audio');
|
||||
|
||||
foreach ($out as $outP)
|
||||
{
|
||||
$infos = explode("\t", $outP);
|
||||
|
||||
if (count($infos) != 2 || $infos[0] != 'Picture')
|
||||
continue;
|
||||
|
||||
$this->log("Some preview datas found in audio file");
|
||||
|
||||
$cmd = sprintf('%s -b -Picture %s > %s'
|
||||
, $this->binary
|
||||
, $this->escapeshellargs($raw_datas->getPathname())
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
if (filesize($dest) > 0)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink($dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
34
lib/classes/binaryAdapter/audio/resample.class.php
Normal file
34
lib/classes/binaryAdapter/audio/resample.class.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_audio_resample extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $processors = array(
|
||||
'binaryAdapter_audio_resample_ffmpeg'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter audio resampler';
|
||||
}
|
||||
|
||||
}
|
51
lib/classes/binaryAdapter/audio/resample/ffmpeg.class.php
Normal file
51
lib/classes/binaryAdapter/audio/resample/ffmpeg.class.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_audio_resample_ffmpeg extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_ffmpeg';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return binaryAdapter_audio_resample_ffmpeg
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$cmd = sprintf('%s -y -i %s %s'
|
||||
, $this->binary
|
||||
, $this->escapeshellargs($origine->getPathname())
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
34
lib/classes/binaryAdapter/document/toFlexpaperSwf.class.php
Normal file
34
lib/classes/binaryAdapter/document/toFlexpaperSwf.class.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_document_toFlexpaperSwf extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $processors = array(
|
||||
'binaryAdapter_document_toFlexpaperSwf_pdf2swf'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter document to flexpaper swf';
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_document_toFlexpaperSwf_pdf2swf extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_pdf2swf';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return binaryAdapter_document_toFlexpaperSwf_pdf2swf
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$system = system_server::get_platform();
|
||||
|
||||
if ($system == 'WINDOWS')
|
||||
{
|
||||
$cmd = sprintf('%s %s %s -s poly2bitmap -T 9 -f'
|
||||
, $this->binary
|
||||
, $this->escapeshellargs($origine->getPathname())
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmd = sprintf('%s %s %s -s poly2bitmap -Q 300 -T 9 -f'
|
||||
, $this->binary
|
||||
, $this->escapeshellargs($origine->getPathname())
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
}
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
34
lib/classes/binaryAdapter/document/toPDF.class.php
Normal file
34
lib/classes/binaryAdapter/document/toPDF.class.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_document_toPDF extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $processors = array(
|
||||
'binaryAdapter_document_toPDF_unoconv'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter document to PDF';
|
||||
}
|
||||
|
||||
}
|
55
lib/classes/binaryAdapter/document/toPDF/unoconv.class.php
Normal file
55
lib/classes/binaryAdapter/document/toPDF/unoconv.class.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_document_toPDF_unoconv extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_unoconv';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return binaryAdapter_document_toPDF_unoconv
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$tmp_file = $this->registry->get('GV_RootPath')
|
||||
. 'tmp/tmp_doc_' . time()
|
||||
. mt_rand(10000, 99999) . '.pdf';
|
||||
|
||||
$cmd = sprintf('%s --format=pdf --stdout %s > %s'
|
||||
, $this->binary
|
||||
, $this->escapeshellargs($origine->getPathname())
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
35
lib/classes/binaryAdapter/flash/toimage.class.php
Normal file
35
lib/classes/binaryAdapter/flash/toimage.class.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_flash_toimage extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $processors = array(
|
||||
'binaryAdapter_flash_toimage_swfextract',
|
||||
'binaryAdapter_flash_toimage_swfrender'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter flash to image';
|
||||
}
|
||||
|
||||
}
|
82
lib/classes/binaryAdapter/flash/toimage/swfextract.class.php
Normal file
82
lib/classes/binaryAdapter/flash/toimage/swfextract.class.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_flash_toimage_swfextract extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_swf_extract';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return binaryAdapter_flash_toimage_swfextract
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$cmd = sprintf('%s %s'
|
||||
, $this->binary
|
||||
, $this->escapeshellargs($origine->getPathname())
|
||||
);
|
||||
|
||||
$stdout = $this->shell_cmd($cmd);
|
||||
|
||||
$id = false;
|
||||
|
||||
foreach ($stdout as $l)
|
||||
{
|
||||
if (substr(trim($l), 0, 4) == '[-j]')
|
||||
{
|
||||
$id = ' -j '
|
||||
. array_pop(explode('-', array_pop(explode(' ', trim($l)))));
|
||||
$ext = '.jpg';
|
||||
break;
|
||||
}
|
||||
if (substr(trim($l), 0, 4) == '[-p]')
|
||||
{
|
||||
$id = ' -p '
|
||||
. array_pop(explode('-', array_pop(explode(' ', trim($l)))));
|
||||
$ext = '.png';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($id)
|
||||
{
|
||||
$cmd = sprintf('%s %s %s -o %s'
|
||||
, $this->binary
|
||||
, $id
|
||||
, $this->escapeshellargs($origine->getPathname())
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
52
lib/classes/binaryAdapter/flash/toimage/swfrender.class.php
Normal file
52
lib/classes/binaryAdapter/flash/toimage/swfrender.class.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_flash_toimage_swfrender extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_swf_render';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return binaryAdapter_flash_toimage_swfrender
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
|
||||
$cmd = sprintf('%s -l %s -o %s'
|
||||
, $this->binary
|
||||
, $this->escapeshellargs($origine->getPathname())
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
33
lib/classes/binaryAdapter/image/resize.class.php
Normal file
33
lib/classes/binaryAdapter/image/resize.class.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Image Resize adpater for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_image_resize extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
protected $processors = array(
|
||||
'binaryAdapter_image_resize_sips',
|
||||
'binaryAdapter_image_resize_imagemagick',
|
||||
'binaryAdapter_image_resize_gd'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter image resizer';
|
||||
}
|
||||
|
||||
}
|
159
lib/classes/binaryAdapter/image/resize/gd.class.php
Normal file
159
lib/classes/binaryAdapter/image/resize/gd.class.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* GD image resize processor for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_image_resize_gd extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'size' => 200,
|
||||
'dpi' => null,
|
||||
'quality' => 75,
|
||||
'strip' => true,
|
||||
'autorotate' => true
|
||||
);
|
||||
protected $binary_name = 'GD';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param registry $registry
|
||||
* @return binaryAdapter_image_resize_gd
|
||||
*/
|
||||
public function __construct(registry $registry)
|
||||
{
|
||||
$this->binary = function_exists('imagecreate');
|
||||
if (!$this->binary)
|
||||
{
|
||||
throw new Exception('GD not installed');
|
||||
}
|
||||
parent::__construct($registry);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return binaryAdapter_image_resize_gd
|
||||
*/
|
||||
protected function set_option($name, $value)
|
||||
{
|
||||
switch ($name)
|
||||
{
|
||||
case 'dpi':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 0 || $value > 32767) ? null : $value;
|
||||
break;
|
||||
case 'quality':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 0 || $value > 100) ? 75 : $value;
|
||||
break;
|
||||
case 'strip':
|
||||
$value = !!$value;
|
||||
break;
|
||||
case 'size':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 0 || $value > 32000) ? 200 : $value;
|
||||
break;
|
||||
}
|
||||
|
||||
parent::set_option($name, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$tech_datas = $origine->get_technical_datas();
|
||||
|
||||
$size = $this->options['size'];
|
||||
|
||||
if (!is_null($size) && !$origine->is_raw_image()
|
||||
&& $tech_datas[system_file::TC_DATAS_WIDTH] < $size && $tech_datas[system_file::TC_DATAS_HEIGHT] < $size)
|
||||
{
|
||||
$size = max($tech_datas[system_file::TC_DATAS_WIDTH], $tech_datas[system_file::TC_DATAS_HEIGHT]);
|
||||
}
|
||||
|
||||
$imag_original = imagecreatefromjpeg($origine->getPathname());
|
||||
|
||||
if ($imag_original)
|
||||
{
|
||||
$w_doc = imagesx($imag_original);
|
||||
$h_doc = imagesy($imag_original);
|
||||
|
||||
if ($w_doc < $size && $h_doc < $size)
|
||||
{
|
||||
$img_mini = imagecreatetruecolor($w_doc, $h_doc);
|
||||
imagecopy($img_mini, $imag_original, 0, 0, 0, 0, $w_doc, $h_doc);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($w_doc > $h_doc)
|
||||
$h_sub = (int) (($h_doc / $w_doc) * ($w_sub = $size));
|
||||
else
|
||||
$w_sub = (int) (($w_doc / $h_doc) * ($h_sub = $size));
|
||||
$img_mini = imagecreatetruecolor($w_sub, $h_sub);
|
||||
|
||||
imagecopyresampled($img_mini, $imag_original, 0, 0, 0, 0,
|
||||
$w_sub, $h_sub, $w_doc, $h_doc);
|
||||
}
|
||||
|
||||
if ($this->options['autorotate'])
|
||||
{
|
||||
switch ($tech_datas[system_file::TC_DATAS_ORIENTATION])
|
||||
{
|
||||
case 3:
|
||||
$img_mini = imagerotate($img_mini, 180, 0);
|
||||
break;
|
||||
case 6:
|
||||
$img_mini = imagerotate($img_mini, 270, 0);
|
||||
$z = $w_sub;
|
||||
$w_sub = $h_sub;
|
||||
$h_sub = $z;
|
||||
break;
|
||||
case 8:
|
||||
$img_mini = imagerotate($img_mini, 90, 0);
|
||||
$z = $w_sub;
|
||||
$w_sub = $h_sub;
|
||||
$h_sub = $z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$quality = $this->options['quality'];
|
||||
|
||||
imagejpeg($img_mini, $dest, $quality);
|
||||
|
||||
imagedestroy($img_mini);
|
||||
imagedestroy($imag_original);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
170
lib/classes/binaryAdapter/image/resize/imagemagick.class.php
Normal file
170
lib/classes/binaryAdapter/image/resize/imagemagick.class.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ImageMagick image resize processor for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_image_resize_imagemagick extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'size' => 200,
|
||||
'dpi' => null,
|
||||
'quality' => 75,
|
||||
'strip' => true,
|
||||
'autorotate' => true
|
||||
);
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_imagick';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return binaryAdapter_image_resize_imagemagick
|
||||
*/
|
||||
protected function set_option($name, $value)
|
||||
{
|
||||
switch ($name)
|
||||
{
|
||||
case 'dpi':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 0 || $value > 32767) ? null : $value;
|
||||
break;
|
||||
case 'quality':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 0 || $value > 100) ? 75 : $value;
|
||||
break;
|
||||
case 'strip':
|
||||
$value = !!$value;
|
||||
break;
|
||||
case 'size':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 0 || $value > 32000) ? 200 : $value;
|
||||
break;
|
||||
}
|
||||
|
||||
parent::set_option($name, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$tech_datas = $origine->get_technical_datas();
|
||||
|
||||
$size = $this->options['size'];
|
||||
$width = isset($tech_datas[system_file::TC_DATAS_WIDTH]) ? $tech_datas[system_file::TC_DATAS_WIDTH] : null;
|
||||
$height = isset($tech_datas[system_file::TC_DATAS_HEIGHT]) ? $tech_datas[system_file::TC_DATAS_HEIGHT] : null;
|
||||
|
||||
if (!is_null($size) && !$origine->is_raw_image() && $width < $size && $height < $size)
|
||||
{
|
||||
$size = max($width, $height);
|
||||
}
|
||||
|
||||
$cmd = $this->binary;
|
||||
|
||||
$cmd .= ' -colorspace RGB -flatten -alpha Off -quiet';
|
||||
|
||||
if ($this->options['strip'])
|
||||
$cmd .= ' -strip';
|
||||
|
||||
$cmd .= sprintf(' -quality %s', $this->options['quality']);
|
||||
|
||||
if ($size)
|
||||
{
|
||||
$cmd .= sprintf(' -resize %sx%s', $size, $size);
|
||||
|
||||
if (in_array(
|
||||
$origine->get_mime(), array(
|
||||
'application/pdf',
|
||||
'application/postscript'
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
$cmd .= sprintf(' -geometry %sx%s', $size, $size);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->options['dpi'])
|
||||
{
|
||||
$cmd .= sprintf(' -density %sx%s -units PixelsPerInch'
|
||||
, $this->options['dpi']
|
||||
, $this->options['dpi']
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->options['autorotate'])
|
||||
{
|
||||
switch ($tech_datas[system_file::TC_DATAS_ORIENTATION])
|
||||
{
|
||||
case 3:
|
||||
$cmd .= ' -rotate 180';
|
||||
break;
|
||||
case 6:
|
||||
$cmd .= ' -rotate 90';
|
||||
break;
|
||||
case 8:
|
||||
$cmd .= ' -rotate -90';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$array = array(
|
||||
'image/tiff',
|
||||
'application/pdf',
|
||||
'image/psd',
|
||||
'image/vnd.adobe.photoshop',
|
||||
'image/photoshop',
|
||||
'image/ai',
|
||||
'image/illustrator',
|
||||
'image/vnd.adobe.illustrator'
|
||||
);
|
||||
|
||||
if (in_array($origine->get_mime(), $array))
|
||||
{
|
||||
$cmd .= sprintf(' %s %s'
|
||||
, $this->escapeshellargs($origine->getPathname(), '[0]')
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmd .= sprintf(' %s %s'
|
||||
, $this->escapeshellargs($origine->getPathname())
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
}
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
153
lib/classes/binaryAdapter/image/resize/sips.class.php
Normal file
153
lib/classes/binaryAdapter/image/resize/sips.class.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SIPS image resize processor for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_image_resize_sips extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'size' => 200,
|
||||
'dpi' => null,
|
||||
'quality' => 75,
|
||||
'strip' => true,
|
||||
'autorotate' => true
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param registry $registry
|
||||
* @return binaryAdapter_imageTransform_sips
|
||||
*/
|
||||
public function __construct(registry $registry)
|
||||
{
|
||||
throw new Exception('Need to work');
|
||||
try
|
||||
{
|
||||
$system = system_server::get_platform();
|
||||
if ($system !== 'DARWIN')
|
||||
throw new Exception('this adapter is not available on this platform');
|
||||
|
||||
$this->binary = new SplFileObject('/usr/bin/sips');
|
||||
|
||||
if (!$this->binary->isExecutable())
|
||||
throw new Exception('Sips is not executable');
|
||||
|
||||
parent::__construct($registry);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return binaryAdapter_image_resize_sips
|
||||
*/
|
||||
protected function set_option($name, $value)
|
||||
{
|
||||
switch ($name)
|
||||
{
|
||||
case 'dpi':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 0 || $value > 32767) ? null : $value;
|
||||
break;
|
||||
case 'quality':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 0 || $value > 100) ? 75 : $value;
|
||||
break;
|
||||
case 'strip':
|
||||
$value = !!$value;
|
||||
break;
|
||||
case 'size':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 0 || $value > 32000) ? 200 : $value;
|
||||
break;
|
||||
}
|
||||
|
||||
parent::set_option($name, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$tech_datas = $origine->get_technical_datas();
|
||||
|
||||
$size = $this->options['size'];
|
||||
|
||||
if ($tech_datas[system_file::TC_DATAS_COLORSPACE] == 'CMYK')
|
||||
throw new Exception('this adapter does not work with CMYK');
|
||||
|
||||
if (!is_null($size) && !$origine->is_raw_image()
|
||||
&& $tech_datas[system_file::TC_DATAS_WIDTH] < $size && $tech_datas[system_file::TC_DATAS_HEIGHT] < $size)
|
||||
{
|
||||
$size = max($tech_datas[system_file::TC_DATAS_WIDTH], $tech_datas[system_file::TC_DATAS_HEIGHT]);
|
||||
}
|
||||
|
||||
$cmd = 'sips'
|
||||
. ' -s format jpeg'
|
||||
. ' -s formatOptions ' . $this->options['quality']
|
||||
. ' -Z ' . $size;
|
||||
|
||||
if ($this->options['dpi'])
|
||||
{
|
||||
$cmd .= ' -s dpiHeight ' . $this->options['dpi']
|
||||
. ' -s dpiWidth ' . $this->options['dpi'];
|
||||
}
|
||||
|
||||
if ($this->options['autorotate'])
|
||||
{
|
||||
switch ($tech_datas[system_file::TC_DATAS_ORIENTATION])
|
||||
{
|
||||
case 3:
|
||||
$cmd .= ' -r 180';
|
||||
break;
|
||||
case 6:
|
||||
$cmd .= ' -r 90';
|
||||
break;
|
||||
case 8:
|
||||
$cmd .= ' -r 270';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$cmd .= sprintf(' %s --out %s'
|
||||
, $this->escapeshellargs($origine->getPathname())
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
31
lib/classes/binaryAdapter/image/rotate.class.php
Normal file
31
lib/classes/binaryAdapter/image/rotate.class.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_image_rotate extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
protected $processors = array(
|
||||
'binaryAdapter_image_rotate_imagemagick'
|
||||
, 'binaryAdapter_image_rotate_gd'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter image rotator';
|
||||
}
|
||||
|
||||
}
|
92
lib/classes/binaryAdapter/image/rotate/gd.class.php
Normal file
92
lib/classes/binaryAdapter/image/rotate/gd.class.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* GD image resize processor for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_image_rotate_gd extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'angle' => 90
|
||||
);
|
||||
protected $binary_name = 'GD';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param registry $registry
|
||||
* @return binaryAdapter_image_resize_gd
|
||||
*/
|
||||
public function __construct(registry $registry)
|
||||
{
|
||||
$this->binary = function_exists('imagecreate');
|
||||
if (!$this->binary)
|
||||
{
|
||||
throw new Exception('GD not installed');
|
||||
}
|
||||
parent::__construct($registry);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return binaryAdapter_image_resize_gd
|
||||
*/
|
||||
protected function set_option($name, $value)
|
||||
{
|
||||
switch ($name)
|
||||
{
|
||||
case 'angle':
|
||||
$value = (int) $value;
|
||||
break;
|
||||
}
|
||||
|
||||
parent::set_option($name, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$type = $origine->get_phrasea_type();
|
||||
|
||||
if ($type !== 'image')
|
||||
throw new Exception('Cant rotate non image files');
|
||||
|
||||
$fichier = $origine->getPathname();
|
||||
$source = imagecreatefromjpeg($fichier);
|
||||
$rot = $this->options['angle'] * -1;
|
||||
$source = imagerotate($source, $rot, 0);
|
||||
imagejpeg($source, $dest, 90);
|
||||
imagedestroy($source);
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
103
lib/classes/binaryAdapter/image/rotate/imagemagick.class.php
Normal file
103
lib/classes/binaryAdapter/image/rotate/imagemagick.class.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ImageMagick image resize processor for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_image_rotate_imagemagick extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'angle' => 90
|
||||
);
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_imagick';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return binaryAdapter_image_resize_imagemagick
|
||||
*/
|
||||
protected function set_option($name, $value)
|
||||
{
|
||||
switch ($name)
|
||||
{
|
||||
case 'angle':
|
||||
$value = (int) $value;
|
||||
break;
|
||||
}
|
||||
|
||||
parent::set_option($name, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$type = $origine->get_phrasea_type();
|
||||
|
||||
if ($type !== 'image')
|
||||
throw new Exception('Cant rotate non image files');
|
||||
|
||||
$cmd = $this->binary;
|
||||
|
||||
$cmd .= ' -rotate ' . $this->options['angle'];
|
||||
|
||||
$array = array(
|
||||
'image/tiff',
|
||||
'application/pdf',
|
||||
'image/psd',
|
||||
'image/vnd.adobe.photoshop',
|
||||
'image/photoshop',
|
||||
'image/ai',
|
||||
'image/illustrator',
|
||||
'image/vnd.adobe.illustrator'
|
||||
);
|
||||
|
||||
if (in_array($origine->get_mime(), $array))
|
||||
{
|
||||
$cmd .= sprintf(' %s %s'
|
||||
, $this->escapeshellargs($origine->getPathname(), '[0]')
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmd .= sprintf(' %s %s'
|
||||
, $this->escapeshellargs($origine->getPathname())
|
||||
, $this->escapeshellargs($dest)
|
||||
);
|
||||
}
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
137
lib/classes/binaryAdapter/processorAbstract.class.php
Normal file
137
lib/classes/binaryAdapter/processorAbstract.class.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract processor object for binaryAdapter
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
abstract class binaryAdapter_processorAbstract extends binaryAdapter_abstract implements binaryAdapter_processorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var system_file
|
||||
*/
|
||||
protected $binary;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_pdf2swf';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param registry $registry
|
||||
* @return binaryAdapter_processorAbstract
|
||||
*/
|
||||
public function __construct(registry $registry)
|
||||
{
|
||||
if (!$this->binary_name)
|
||||
throw new Exception('/!\ binary_name must be set to use this class');
|
||||
if ($this->binary == null)
|
||||
{
|
||||
$binary = new SplFileObject($registry->get($this->binary_name));
|
||||
if (!$binary->isExecutable())
|
||||
throw new Exception($this->binary_name . ' is not executable');
|
||||
$this->binary = $binary;
|
||||
}
|
||||
$this->registry = $registry;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @param array $options
|
||||
* @return system_file
|
||||
*/
|
||||
public function execute(system_file $origine, $dest, Array $options)
|
||||
{
|
||||
$this->set_options($options);
|
||||
$this->process($origine, $dest);
|
||||
|
||||
if (!$dest)
|
||||
$dest = $origine->getPathname();
|
||||
|
||||
return new system_file($dest);
|
||||
}
|
||||
|
||||
protected abstract function process(system_file $raw_datas, $dest);
|
||||
|
||||
/**
|
||||
* Escape file arguments
|
||||
*
|
||||
* @param string $arg
|
||||
* @param string $file_option
|
||||
* @return string
|
||||
*/
|
||||
protected function escapeshellargs($arg, $file_option='')
|
||||
{
|
||||
$file = escapeshellcmd($arg) . $file_option;
|
||||
|
||||
return escapeshellarg($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch provided command in shell, returns stdout
|
||||
*
|
||||
* @param string $cmd
|
||||
* @return array
|
||||
*/
|
||||
protected function shell_cmd($cmd)
|
||||
{
|
||||
|
||||
if ($this->debug)
|
||||
{
|
||||
$message = "****************************************************";
|
||||
$message .= "\n\t\t*\n\t\t*\tExecution commande :\n\t\t*\n\t\t*\t\t";
|
||||
$message .= $cmd;
|
||||
$message .= "\n\t\t*\n\t\t";
|
||||
$message .= "****************************************************";
|
||||
$this->log($message);
|
||||
}
|
||||
|
||||
$system = system_server::get_platform();
|
||||
|
||||
if ($system == 'WINDOWS')
|
||||
$cmd = 'start /B /WAIT /LOW ' . $cmd;
|
||||
|
||||
exec($cmd, $return);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $pathfile
|
||||
* @param string $extension
|
||||
* @return string
|
||||
*/
|
||||
protected function set_extension($pathfile, $extension)
|
||||
{
|
||||
$pathinfo = pathinfo($pathfile);
|
||||
$current_extension = isset($pathinfo['extension']) ?
|
||||
$pathinfo['extension'] : '';
|
||||
|
||||
return mb_substr(
|
||||
$pathfile, 0,
|
||||
(mb_strlen($pathfile) - mb_strlen($current_extension))
|
||||
)
|
||||
. $extension;
|
||||
}
|
||||
|
||||
}
|
28
lib/classes/binaryAdapter/processorInterface.class.php
Normal file
28
lib/classes/binaryAdapter/processorInterface.class.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Processor interface for binaryAdapter
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
interface binaryAdapter_processorInterface
|
||||
{
|
||||
public function __construct(registry $registry);
|
||||
|
||||
public function execute(system_file $origine, $dest, Array $options);
|
||||
|
||||
public function set_options($options);
|
||||
|
||||
public function log($message);
|
||||
}
|
31
lib/classes/binaryAdapter/rawImage/previewExtract.class.php
Normal file
31
lib/classes/binaryAdapter/rawImage/previewExtract.class.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* RawImage preview extractor adpater for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_rawImage_previewExtract extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
protected $processors = array(
|
||||
'binaryAdapter_rawImage_previewExtract_exiftool'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter rawImage preview Extractor';
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exiftool preview extractor from raw images processor
|
||||
* for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_rawImage_previewExtract_exiftool extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_exiftool';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $raw_datas
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $raw_datas, $dest)
|
||||
{
|
||||
if (!$raw_datas->is_raw_image())
|
||||
throw new Exception('Provided file is not raw image datas');
|
||||
|
||||
$tmpFiles = array();
|
||||
|
||||
$cmd = $this->binary;
|
||||
|
||||
$thisFile = $tmpFiles[] = $this->registry->get('GV_RootPath')
|
||||
. 'tmp/' . time() . '-PI';
|
||||
|
||||
$cmd .= sprintf(' -b -PreviewImage %s > %s'
|
||||
, $this->escapeshellargs($raw_datas->getPathname())
|
||||
, $this->escapeshellargs($thisFile)
|
||||
);
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
$cmd = $this->binary;
|
||||
|
||||
$thisFile = $tmpFiles[] = $this->registry->get('GV_RootPath')
|
||||
. 'tmp/' . time() . '-JP';
|
||||
|
||||
$cmd .= sprintf(' -b -JpgFromRaw %s > %s'
|
||||
, $this->escapeshellargs($raw_datas->getPathname())
|
||||
, $this->escapeshellargs($thisFile)
|
||||
);
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
$refSize = 0;
|
||||
$tmpFile = false;
|
||||
|
||||
foreach ($tmpFiles as $file)
|
||||
{
|
||||
if (is_file($file) && filesize($file) > 0)
|
||||
{
|
||||
if (filesize($file) > $refSize)
|
||||
{
|
||||
$tmpFile = $file;
|
||||
$refSize = filesize($file);
|
||||
}
|
||||
else
|
||||
unlink($file);
|
||||
}
|
||||
else
|
||||
unlink($file);
|
||||
}
|
||||
if (!$tmpFile)
|
||||
throw new Exception('Unable to extract a preview for the raw imageFile');
|
||||
|
||||
rename($tmpFile, $dest);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
31
lib/classes/binaryAdapter/video/gif.class.php
Normal file
31
lib/classes/binaryAdapter/video/gif.class.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gif from video generator adpater for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_video_gif extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
protected $processors = array(
|
||||
'binaryAdapter_video_gif_ffmpeg'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter video to gif animation';
|
||||
}
|
||||
|
||||
}
|
124
lib/classes/binaryAdapter/video/gif/ffmpeg.class.php
Normal file
124
lib/classes/binaryAdapter/video/gif/ffmpeg.class.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* FFMPEG video to processor for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_video_gif_ffmpeg extends binaryAdapter_video_processorAbstract implements binaryAdapter_processorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'size' => null
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_ffmpeg';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$this->log('GENERATING anim gif');
|
||||
|
||||
$tmpDir = $this->registry->get('GV_RootPath') . 'tmp/' . 'tmp' . time();
|
||||
system_file::mkdir($tmpDir);
|
||||
$tmpDir = p4string::addEndSlash($tmpDir);
|
||||
|
||||
$dimensions = $this->get_dimensions($origine, $this->options['size']);
|
||||
$newHeight = $dimensions['height'];
|
||||
$newWidth = $dimensions['width'];
|
||||
|
||||
$system = system_server::get_platform();
|
||||
|
||||
if ($system == 'WINDOWS')
|
||||
{
|
||||
$cmd = $this->registry->get('GV_ffmpeg')
|
||||
. ' -i ' . $this->escapeshellargs($origine->getPathname())
|
||||
. ' -s ' . $newWidth . 'x' . $newHeight
|
||||
. ' -r 1 -f image2 '
|
||||
. $tmpDir . 'images%05d.jpg';
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmd = $this->binary
|
||||
. ' -i ' . $this->escapeshellargs($origine->getPathname())
|
||||
. ' -s ' . $newWidth . 'x' . $newHeight
|
||||
. ' -r 1 -f image2 '
|
||||
. $this->escapeshellargs($tmpDir) . 'images%05d.jpg';
|
||||
}
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
$files = array();
|
||||
|
||||
|
||||
foreach (new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($tmpDir),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY
|
||||
) as $file)
|
||||
{
|
||||
if ($file->isDir() || strpos($file->getPathname(), '/.svn/') !== false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ($file->isFile())
|
||||
{
|
||||
$filename = $file->getFilename();
|
||||
$files[$filename] = $file->getPathname();
|
||||
}
|
||||
}
|
||||
|
||||
ksort($files);
|
||||
|
||||
$n = count($files);
|
||||
|
||||
$inter = round(count($files) / 10);
|
||||
|
||||
|
||||
$i = 0;
|
||||
foreach ($files as $k => $file)
|
||||
{
|
||||
if ($i % $inter !== 0)
|
||||
{
|
||||
if (unlink($file))
|
||||
unset($files[$k]);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$cmd = $this->registry->get('GV_imagick')
|
||||
. ' -delay 100 -loop 0 ' . $tmpDir . '*.jpg ' . $dest;
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
foreach ($files as $file)
|
||||
unlink($file);
|
||||
|
||||
rmdir($tmpDir);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
101
lib/classes/binaryAdapter/video/processorAbstract.class.php
Normal file
101
lib/classes/binaryAdapter/video/processorAbstract.class.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract video adapter object for binaryAdapter
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
abstract class binaryAdapter_video_processorAbstract extends binaryAdapter_processorAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $value
|
||||
* @param int $multiple
|
||||
* @param string $bound
|
||||
* @return int
|
||||
*/
|
||||
protected function get_multiple($value, $multiple, $bound='nearest')
|
||||
{
|
||||
$modulo = $value % $multiple;
|
||||
|
||||
$ret = 0;
|
||||
|
||||
if ($bound == 'nearest')
|
||||
{
|
||||
$half_distance = $multiple / 2;
|
||||
if ($modulo <= $half_distance)
|
||||
$bound = 'bottom';
|
||||
else
|
||||
$bound = 'top';
|
||||
}
|
||||
|
||||
switch ($bound)
|
||||
{
|
||||
default:
|
||||
case 'top':
|
||||
$ret = $value + $multiple - $modulo;
|
||||
break;
|
||||
case 'bottom':
|
||||
$ret = $value - $modulo;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($ret < $multiple)
|
||||
$ret = $multiple;
|
||||
|
||||
return (int) $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param int $size
|
||||
* @return array
|
||||
*/
|
||||
protected function get_dimensions(system_file $origine, $size)
|
||||
{
|
||||
|
||||
$tech_datas = $origine->get_technical_datas();
|
||||
|
||||
$maxSize = $this->get_multiple($size, 16, 'bottom');
|
||||
|
||||
$srcWidth = $tech_datas[system_file::TC_DATAS_WIDTH];
|
||||
$srcHeight = $tech_datas[system_file::TC_DATAS_HEIGHT];
|
||||
|
||||
if ($srcWidth > $maxSize || $srcHeight > $maxSize)
|
||||
{
|
||||
if ($srcWidth >= $srcHeight)
|
||||
{
|
||||
$newWidth = (int) $maxSize;
|
||||
$height = round($newWidth * $srcHeight / $srcWidth);
|
||||
$newHeight = $this->get_multiple($height, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
$newHeight = (int) $maxSize;
|
||||
$width = round($newHeight * $srcWidth / $srcHeight);
|
||||
$newWidth = $this->get_multiple($width, 16);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$newHeight = $this->get_multiple($srcHeight, 16);
|
||||
$newWidth = $this->get_multiple($srcWidth, 16);
|
||||
}
|
||||
|
||||
return array('width' => $newWidth, 'height' => $newHeight);
|
||||
}
|
||||
|
||||
}
|
32
lib/classes/binaryAdapter/video/progressive.class.php
Normal file
32
lib/classes/binaryAdapter/video/progressive.class.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* MP4 Progressive adpater for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_video_progressive extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
protected $processors = array(
|
||||
'binaryAdapter_video_progressive_mp4box',
|
||||
'binaryAdapter_video_progressive_moovRelocator'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter video progressive download';
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
require_once dirname(__FILE__) . '/../../../../vendor/moov/relocator.class.php';
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* moovRelocator progressive mp4 processor for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_video_progressive_moovRelocator extends binaryAdapter_video_processorAbstract implements binaryAdapter_processorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'size' => null
|
||||
);
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'MoovRelocator';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary = '/usr/bin/php';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$mp4_file = $origine->getPathname();
|
||||
|
||||
$moovrelocator = moov_relocator::getInstance();
|
||||
|
||||
$ret = $moovrelocator->setInput($mp4_file);
|
||||
|
||||
if ($ret !== true)
|
||||
throw new Exception('File format not ok');
|
||||
|
||||
$ret = $moovrelocator->setOutput($dest);
|
||||
|
||||
if ($ret !== true)
|
||||
throw new Exception('File output error');
|
||||
|
||||
$ret = $moovrelocator->fix();
|
||||
|
||||
if ($ret !== true)
|
||||
throw new Exception('Error while fixing');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
51
lib/classes/binaryAdapter/video/progressive/mp4box.class.php
Normal file
51
lib/classes/binaryAdapter/video/progressive/mp4box.class.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* MP4Box progressive mp4 processor for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_video_progressive_mp4box extends binaryAdapter_video_processorAbstract implements binaryAdapter_processorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_mp4box';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$cmd = sprintf("%s -inter 0.5 %s -out %s"
|
||||
, $this->binary
|
||||
, $this->escapeshellargs($origine->getPathname())
|
||||
, $this->escapeshellargs($dest));
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
31
lib/classes/binaryAdapter/video/resize.class.php
Normal file
31
lib/classes/binaryAdapter/video/resize.class.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Video resizer adpater for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_video_resize extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
protected $processors = array(
|
||||
'binaryAdapter_video_resize_ffmpeg'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter video resizer';
|
||||
}
|
||||
|
||||
}
|
235
lib/classes/binaryAdapter/video/resize/ffmpeg.class.php
Normal file
235
lib/classes/binaryAdapter/video/resize/ffmpeg.class.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* FFMPEG video resize processor for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_video_resize_ffmpeg extends binaryAdapter_video_processorAbstract implements binaryAdapter_processorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'size' => 400,
|
||||
'fps' => 25,
|
||||
'threads' => 1,
|
||||
'bitrate' => 1000,
|
||||
'v_codec' => 'libx264',
|
||||
'a_codec' => 'libfaac'
|
||||
);
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_ffmpeg';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return binaryAdapter_video_resize_ffmpeg
|
||||
*/
|
||||
protected function set_option($name, $value)
|
||||
{
|
||||
switch ($name)
|
||||
{
|
||||
case 'fps':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 1 || $value > 200) ? 25 : $value;
|
||||
break;
|
||||
case 'threads':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 1 || $value > 32) ? 1 : $value;
|
||||
break;
|
||||
case 'bitrate':
|
||||
$value = (int) $value;
|
||||
$value = ($value <= 100 || $value > 50000) ? 1000 : $value;
|
||||
break;
|
||||
case 'v_codec':
|
||||
$v_codecs = array(
|
||||
'x264' => 'libx264',
|
||||
'h264' => 'libx264',
|
||||
'libx264' => 'libx264',
|
||||
'libh264' => 'h264',
|
||||
'flv' => 'flv',
|
||||
'flash' => 'flv'
|
||||
);
|
||||
$value = array_key_exists($value, $v_codecs) ? $v_codecs[$value] : 'libx264';
|
||||
break;
|
||||
case 'a_codec':
|
||||
|
||||
$a_codecs = array(
|
||||
'faac' => 'libfaac',
|
||||
'libfaac' => 'libfaac',
|
||||
'mp3' => 'libmp3lame'
|
||||
);
|
||||
$value = array_key_exists($value, $a_codecs) ? $a_codecs[$value] : 'libfaac';
|
||||
break;
|
||||
}
|
||||
|
||||
parent::set_option($name, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
|
||||
$tech_datas = $origine->get_technical_datas();
|
||||
|
||||
$srcWidth = $tech_datas[system_file::TC_DATAS_WIDTH];
|
||||
$srcHeight = $tech_datas[system_file::TC_DATAS_HEIGHT];
|
||||
$srcFPS = $tech_datas[system_file::TC_DATAS_FRAMERATE];
|
||||
$srcAR = isset($tech_datas[system_file::TC_DATAS_AUDIOSAMPLERATE]) ?
|
||||
$tech_datas[system_file::TC_DATAS_AUDIOSAMPLERATE] : null;
|
||||
$srcAB = isset($tech_datas[system_file::TC_DATAS_AUDIOBITRATE]) ?
|
||||
intval($tech_datas[system_file::TC_DATAS_AUDIOBITRATE] / 1000) : null;
|
||||
|
||||
$dimensions = $this->get_dimensions($origine, $this->options['size']);
|
||||
|
||||
$newHeight = $dimensions['height'];
|
||||
$newWidth = $dimensions['width'];
|
||||
|
||||
$cwd = getcwd();
|
||||
chdir($this->registry->get('GV_RootPath') . 'tmp/');
|
||||
|
||||
if ($this->debug)
|
||||
$this->log("GENERATING video ");
|
||||
|
||||
if ($this->options['v_codec'] == 'flv')
|
||||
$dest = $this->set_extension($dest, 'flv');
|
||||
else
|
||||
$dest = $this->set_extension($dest, 'mp4');
|
||||
|
||||
$dest_pass1 = $dest . '-tmp.mp4';
|
||||
|
||||
$system = system_server::get_platform();
|
||||
|
||||
if ($system == 'WINDOWS')
|
||||
{
|
||||
$cmd_part1 = $this->binary->getPathname()
|
||||
. ' -y -i \''
|
||||
. str_replace('/', "\\", $origine->getPathname()) . '\' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmd_part1 = $this->binary->getPathname()
|
||||
. ' -y -i '
|
||||
. $this->escapeshellargs($origine->getPathname()) . ' ';
|
||||
}
|
||||
|
||||
if (in_array($this->options['v_codec'], array('libx264', 'h264')))
|
||||
{
|
||||
|
||||
$cmd_part2 = ' -s ' . $newWidth . 'x' . $newHeight
|
||||
. ' -r ' . $this->options['fps']
|
||||
. ' -vcodec ' . trim($this->options['v_codec'])
|
||||
. ' -b ' . trim($this->options['bitrate']) . 'k -g 25 -bf 3'
|
||||
. ' -threads ' . $this->options['threads']
|
||||
. ' -refs 6 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 '
|
||||
. ' -sc_threshold 40 -flags +loop -cmp +chroma'
|
||||
. ' -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 '
|
||||
. ' -directpred 3 -flags2 +dct8x8+wpred+bpyramid+mixed_refs'
|
||||
. ' -trellis 1 '
|
||||
. ' -partitions +parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 '
|
||||
. '-acodec ' . trim($this->options['a_codec']) . ' -ab 92k ';
|
||||
|
||||
$cmd_pass1 = $cmd_part1 . ' -pass 1 ' . $cmd_part2
|
||||
. ' -an ' . $this->escapeshellargs($dest_pass1);
|
||||
$cmd_pass2 = $cmd_part1 . ' -pass 2 ' . $cmd_part2
|
||||
. ' -ac 2 -ar 44100 ' . $this->escapeshellargs($dest);
|
||||
|
||||
if (is_file($dest))
|
||||
unlink($dest);
|
||||
|
||||
$this->shell_cmd($cmd_pass1);
|
||||
|
||||
$this->shell_cmd($cmd_pass2);
|
||||
|
||||
$files = array(
|
||||
'ffmpeg2pass-0.log',
|
||||
'x264_2pass.log',
|
||||
'x264_2pass.log.mbtree'
|
||||
);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if (is_file($file))
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
if (is_file($dest_pass1))
|
||||
unlink($dest_pass1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$audioEnc = '';
|
||||
if (trim($srcAB) != '' && trim($srcAB) != '')
|
||||
{
|
||||
$okMp3BR = array('44100' => true, '22050' => true, '11025' => true);
|
||||
if (!isset($srcAR)
|
||||
|| trim($srcAR) == ''
|
||||
|| !array_key_exists($srcAR, $okMp3BR))
|
||||
{
|
||||
$srcAR = '44100';
|
||||
}
|
||||
|
||||
if ($srcAB == '0' || trim($srcAB) == '')
|
||||
$srcAB = '0';
|
||||
|
||||
$audioEnc = ' -ar ' . $srcAR
|
||||
. ' -ab ' . $srcAB . 'k -acodec libmp3lame ';
|
||||
}
|
||||
|
||||
if ($system == 'WINDOWS')
|
||||
{
|
||||
$cmd = $this->binary->getPathname()
|
||||
. ' -y -i \''
|
||||
. str_replace('/', "\\", $origine->getPathname()) . '\' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmd = $this->binary->getPathname()
|
||||
. ' -y -i '
|
||||
. $this->escapeshellargs($origine->getPathname()) . ' ';
|
||||
}
|
||||
|
||||
$cmd .= $audioEnc .
|
||||
' -f flv -nr 500 -s ' . $newWidth . 'x' . $newHeight . '' .
|
||||
' -r ' . $this->options['fps'] .
|
||||
' -b 270k -me_range ' . $srcFPS
|
||||
. ' -i_qfactor 0.71 -g 500 ' . $this->escapeshellargs($dest);
|
||||
|
||||
|
||||
if ($this->debug)
|
||||
$this->log("execution commande : " . $cmd_pass2);
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
}
|
||||
|
||||
chdir($cwd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
31
lib/classes/binaryAdapter/video/toimage.class.php
Normal file
31
lib/classes/binaryAdapter/video/toimage.class.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Video image extractor adpater for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_video_toimage extends binaryAdapter_adapterAbstract
|
||||
{
|
||||
|
||||
protected $processors = array(
|
||||
'binaryAdapter_video_toimage_ffmpeg'
|
||||
);
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return 'Binary adapter video to image';
|
||||
}
|
||||
|
||||
}
|
106
lib/classes/binaryAdapter/video/toimage/ffmpeg.class.php
Normal file
106
lib/classes/binaryAdapter/video/toimage/ffmpeg.class.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* FFMPEG image from video extractor processor for binaryAdapter package
|
||||
*
|
||||
* @package binaryAdapter
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class binaryAdapter_video_toimage_ffmpeg extends binaryAdapter_video_processorAbstract implements binaryAdapter_processorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'size' => null
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary_name = 'GV_ffmpeg';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $dest
|
||||
* @return system_file
|
||||
*/
|
||||
protected function process(system_file $origine, $dest)
|
||||
{
|
||||
$tmpDir = $this->registry->get('GV_RootPath')
|
||||
. 'tmp/' . 'tmp' . time() . '/';
|
||||
system_file::mkdir($tmpDir);
|
||||
|
||||
$tmpFile = $tmpDir . 'extract-tmp.jpg';
|
||||
|
||||
$tech_datas = $origine->get_technical_datas();
|
||||
|
||||
$time_tot = $tech_datas[system_file::TC_DATAS_DURATION];
|
||||
$time_cut = max(round($tech_datas[system_file::TC_DATAS_DURATION] * 0.6), 1);
|
||||
|
||||
$system = system_server::get_platform();
|
||||
|
||||
|
||||
if ($this->debug)
|
||||
$this->log("Duree totale : " . $tech_datas[system_file::TC_DATAS_DURATION]);
|
||||
|
||||
$dimensions = $this->get_dimensions($origine, $this->options['size']);
|
||||
|
||||
$newHeight = $dimensions['height'];
|
||||
$newWidth = $dimensions['width'];
|
||||
|
||||
$system = system_server::get_platform();
|
||||
|
||||
if ($system == 'WINDOWS')
|
||||
{
|
||||
$cmd = $this->binary
|
||||
. ' -i ' . $this->escapeshellargs($origine->getPathname())
|
||||
. ' -s ' . $newWidth . 'x' . $newHeight
|
||||
. ' -vframes 1 -ss ' . $time_cut
|
||||
. ' -f image2 ' . $this->escapeshellargs($tmpFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmd = $this->binary
|
||||
. ' -i ' . $this->escapeshellargs($origine->getPathname())
|
||||
. ' -s ' . $newWidth . 'x' . $newHeight
|
||||
. ' -vframes 1 -ss ' . $time_cut
|
||||
. ' -f image2 ' . $this->escapeshellargs($tmpFile);
|
||||
}
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
|
||||
if ($this->debug)
|
||||
$this->log("Commande executee : $cmd \n");
|
||||
|
||||
if (!file_exists($tmpFile))
|
||||
throw new Exception('Unable to extract image');
|
||||
|
||||
$cmd = $this->registry->get('GV_pathcomposite')
|
||||
. ' -gravity SouthEast -quiet -compose over "'
|
||||
. $this->registry->get('GV_RootPath') . 'www/skins/icons/play.png"'
|
||||
. ' ' . $this->escapeshellargs($tmpFile)
|
||||
. ' ' . $this->escapeshellargs($dest);
|
||||
|
||||
$this->shell_cmd($cmd);
|
||||
unlink($tmpFile);
|
||||
rmdir($tmpDir);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user