本文整理汇总了PHP中OC_Image::scaleDownToFit方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Image::scaleDownToFit方法的具体用法?PHP OC_Image::scaleDownToFit怎么用?PHP OC_Image::scaleDownToFit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Image
的用法示例。
在下文中一共展示了OC_Image::scaleDownToFit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getThumbnail
/**
* {@inheritDoc}
*/
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
//get fileinfo
$fileInfo = $fileview->getFileInfo($path);
if (!$fileInfo) {
return false;
}
$maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50);
$size = $fileInfo->getSize();
if ($maxSizeForImages !== -1 && $size > $maxSizeForImages * 1024 * 1024) {
return false;
}
$image = new \OC_Image();
$useTempFile = $fileInfo->isEncrypted() || !$fileInfo->getStorage()->isLocal();
if ($useTempFile) {
$fileName = $fileview->toTmpFile($path);
} else {
$fileName = $fileview->getLocalFile($path);
}
$image->loadFromFile($fileName);
$image->fixOrientation();
if ($useTempFile) {
unlink($fileName);
}
if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
return $image;
}
return false;
}
示例2: getThumbnail
/**
* {@inheritDoc}
*/
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
$this->initCmd();
if (is_null($this->cmd)) {
return false;
}
$absPath = $fileview->toTmpFile($path);
$tmpDir = \OC::$server->getTempManager()->getTempBaseDir();
$defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
$clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
$exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
shell_exec($exec);
//create imagick object from pdf
$pdfPreview = null;
try {
list($dirname, , , $filename) = array_values(pathinfo($absPath));
$pdfPreview = $dirname . '/' . $filename . '.pdf';
$pdf = new \imagick($pdfPreview . '[0]');
$pdf->setImageFormat('jpg');
} catch (\Exception $e) {
unlink($absPath);
unlink($pdfPreview);
\OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::ERROR);
return false;
}
$image = new \OC_Image();
$image->loadFromData($pdf);
unlink($absPath);
unlink($pdfPreview);
if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
return $image;
}
return false;
}
示例3: getThumbnail
/**
* {@inheritDoc}
*/
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
try {
$svg = new \Imagick();
$svg->setBackgroundColor(new \ImagickPixel('transparent'));
$content = stream_get_contents($fileview->fopen($path, 'r'));
if (substr($content, 0, 5) !== '<?xml') {
$content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
}
// Do not parse SVG files with references
if (stripos($content, 'xlink:href') !== false) {
return false;
}
$svg->readImageBlob($content);
$svg->setImageFormat('png32');
} catch (\Exception $e) {
\OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::ERROR);
return false;
}
//new image object
$image = new \OC_Image();
$image->loadFromData($svg);
//check if image object is valid
if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
return $image;
}
return false;
}
示例4: getThumbnail
/**
* {@inheritDoc}
*/
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
$getID3 = new \getID3();
$tmpPath = $fileview->toTmpFile($path);
$tags = $getID3->analyze($tmpPath);
\getid3_lib::CopyTagsToComments($tags);
if (isset($tags['id3v2']['APIC'][0]['data'])) {
$picture = @$tags['id3v2']['APIC'][0]['data'];
unlink($tmpPath);
$image = new \OC_Image();
$image->loadFromData($picture);
if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
return $image;
}
}
return $this->getNoCoverThumbnail();
}
示例5: getThumbnail
/**
* {@inheritDoc}
*/
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
$getID3 = new ID3Parser();
$tmpPath = $fileview->toTmpFile($path);
$tags = $getID3->analyze($tmpPath);
unlink($tmpPath);
$picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null;
if (is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) {
$picture = $tags['id3v2']['PIC'][0]['data'];
}
if (!is_null($picture)) {
$image = new \OC_Image();
$image->loadFromData($picture);
if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
return $image;
}
}
return $this->getNoCoverThumbnail();
}
示例6: generateThumbNail
/**
* @param int $maxX
* @param int $maxY
* @param string $absPath
* @param int $second
* @return bool|\OCP\IImage
*/
private function generateThumbNail($maxX, $maxY, $absPath, $second)
{
$tmpPath = \OC_Helper::tmpFile();
if (self::$avconvBinary) {
$cmd = self::$avconvBinary . ' -an -y -ss ' . escapeshellarg($second) . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1';
} else {
$cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1' . ' ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1';
}
exec($cmd, $output, $returnCode);
if ($returnCode === 0) {
$image = new \OC_Image();
$image->loadFromFile($tmpPath);
unlink($tmpPath);
if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
return $image;
}
}
unlink($tmpPath);
return false;
}
示例7: testScaleDownWhenBigger
/**
* @dataProvider largeSampleProvider
*
* @param string $filename
* @param int[] $asked
* @param int[] $expected
*/
public function testScaleDownWhenBigger($filename, $asked, $expected)
{
$img = new \OC_Image(OC::$SERVERROOT . '/tests/data/' . $filename);
//$this->assertTrue($img->scaleDownToFit($asked[0], $asked[1]));
$img->scaleDownToFit($asked[0], $asked[1]);
$this->assertEquals($expected[0], $img->width());
$this->assertEquals($expected[1], $img->height());
}