本文整理汇总了PHP中OC_Image::valid方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Image::valid方法的具体用法?PHP OC_Image::valid怎么用?PHP OC_Image::valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Image
的用法示例。
在下文中一共展示了OC_Image::valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postAvatar
public static function postAvatar($args)
{
\OC_JSON::checkLoggedIn();
\OC_JSON::callCheck();
$user = \OC_User::getUser();
if (isset($_POST['path'])) {
$path = stripslashes($_POST['path']);
$view = new \OC\Files\View('/' . $user . '/files');
$fileInfo = $view->getFileInfo($path);
if ($fileInfo['encrypted'] === true) {
$fileName = $view->toTmpFile($path);
} else {
$fileName = $view->getLocalFile($path);
}
} elseif (!empty($_FILES)) {
$files = $_FILES['files'];
if ($files['error'][0] === 0 && is_uploaded_file($files['tmp_name'][0]) && !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0])) {
\OC\Cache::set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200);
$view = new \OC\Files\View('/' . $user . '/cache');
$fileName = $view->getLocalFile('avatar_upload');
unlink($files['tmp_name'][0]);
}
} else {
$l = new \OC_L10n('core');
\OC_JSON::error(array("data" => array("message" => $l->t("No image or file provided"))));
return;
}
try {
$image = new \OC_Image();
$image->loadFromFile($fileName);
$image->fixOrientation();
if ($image->valid()) {
\OC\Cache::set('tmpavatar', $image->data(), 7200);
\OC_JSON::error(array("data" => "notsquare"));
} else {
$l = new \OC_L10n('core');
$mimeType = $image->mimeType();
if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') {
\OC_JSON::error(array("data" => array("message" => $l->t("Unknown filetype"))));
}
if (!$image->valid()) {
\OC_JSON::error(array("data" => array("message" => $l->t("Invalid image"))));
}
}
} catch (\Exception $e) {
\OC_JSON::error(array("data" => array("message" => $e->getMessage())));
}
}
示例2: getThumbnail
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
$this->initCmd();
if (is_null($this->cmd)) {
return false;
}
$absPath = $fileview->toTmpFile($path);
$tmpDir = get_temp_dir();
$defaultParameters = ' --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);
$export = 'export HOME=/' . $tmpDir;
shell_exec($export . "\n" . $exec);
//create imagick object from pdf
try {
$pdf = new \imagick($absPath . '.pdf' . '[0]');
$pdf->setImageFormat('jpg');
} catch (\Exception $e) {
unlink($absPath);
unlink($absPath . '.pdf');
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
return false;
}
$image = new \OC_Image();
$image->loadFromData($pdf);
unlink($absPath);
unlink($absPath . '.pdf');
return $image->valid() ? $image : false;
}
示例3: getThumbnail
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
// TODO: use proc_open() and stream the source file ?
$absPath = \OC_Helper::tmpFile();
$tmpPath = \OC_Helper::tmpFile();
$handle = $fileview->fopen($path, 'rb');
// we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB.
// in some cases 1MB was no enough to generate thumbnail
$firstmb = stream_get_contents($handle, 5242880);
file_put_contents($absPath, $firstmb);
if (self::$avconvBinary) {
$cmd = self::$avconvBinary . ' -an -y -ss 5' . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1';
} else {
$cmd = self::$ffmpegBinary . ' -y -ss 5' . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1' . ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1';
}
exec($cmd, $output, $returnCode);
unlink($absPath);
if ($returnCode === 0) {
$image = new \OC_Image();
$image->loadFromFile($tmpPath);
unlink($tmpPath);
return $image->valid() ? $image : false;
}
return false;
}
示例4: getThumbnail
/**
* @param string $path
* @param int $maxX
* @param int $maxY
* @param boolean $scalingup
* @param \OC\Files\View $fileview
* @return bool|\OC_Image
*/
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
$content = $fileview->fopen($path, 'r');
$content = stream_get_contents($content);
//don't create previews of empty text files
if (trim($content) === '') {
return false;
}
$lines = preg_split("/\r\n|\n|\r/", $content);
$fontSize = 5;
//5px
$lineSize = ceil($fontSize * 1.25);
$image = imagecreate($maxX, $maxY);
imagecolorallocate($image, 255, 255, 255);
$textColor = imagecolorallocate($image, 0, 0, 0);
foreach ($lines as $index => $line) {
$index = $index + 1;
$x = (int) 1;
$y = (int) ($index * $lineSize) - $fontSize;
imagestring($image, 1, $x, $y, $line, $textColor);
if ($index * $lineSize >= $maxY) {
break;
}
}
$image = new \OC_Image($image);
return $image->valid() ? $image : false;
}
示例5: getThumbnail
public function getThumbnail($path)
{
$gallery_path = \OCP\Config::getSystemValue('datadirectory') . '/' . \OC_User::getUser() . '/gallery';
if (file_exists($gallery_path . $path)) {
return new \OC_Image($gallery_path . $path);
}
if (!\OC_Filesystem::file_exists($path)) {
\OC_Log::write(self::TAG, 'File ' . $path . ' don\'t exists', \OC_Log::WARN);
return false;
}
$image = new \OC_Image();
$image->loadFromFile(\OC_Filesystem::getLocalFile($path));
if (!$image->valid()) {
return false;
}
$image->fixOrientation();
$ret = $image->preciseResize(floor(150 * $image->width() / $image->height()), 150);
if (!$ret) {
\OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR);
unset($image);
return false;
}
$image->save($gallery_path . '/' . $path);
return $image;
}
示例6: getThumbnail
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) {
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
return false;
}
//new image object
$image = new \OC_Image();
$image->loadFromData($svg);
//check if image object is valid
return $image->valid() ? $image : false;
}
示例7: set
/**
* sets the users avatar
* @param \OC_Image|resource|string $data OC_Image, imagedata or path to set a new avatar
* @throws Exception if the provided file is not a jpg or png image
* @throws Exception if the provided image is not valid
* @throws \OC\NotSquareException if the image is not square
* @return void
*/
public function set($data)
{
if ($data instanceof OC_Image) {
$img = $data;
$data = $img->data();
} else {
$img = new OC_Image($data);
}
$type = substr($img->mimeType(), -3);
if ($type === 'peg') {
$type = 'jpg';
}
if ($type !== 'jpg' && $type !== 'png') {
$l = \OC_L10N::get('lib');
throw new \Exception($l->t("Unknown filetype"));
}
if (!$img->valid()) {
$l = \OC_L10N::get('lib');
throw new \Exception($l->t("Invalid image"));
}
if (!($img->height() === $img->width())) {
throw new \OC\NotSquareException();
}
$this->view->unlink('avatar.jpg');
$this->view->unlink('avatar.png');
$this->view->file_put_contents('avatar.' . $type, $data);
}
示例8: 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;
}
示例9: getThumbnail
public static function getThumbnail($image_name, $owner = null)
{
if (!$owner) {
$owner = OCP\USER::getUser();
}
$save_dir = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/gallery/';
$save_dir .= dirname($image_name) . '/';
$image_path = $image_name;
$thumb_file = $save_dir . basename($image_name);
if (!is_dir($save_dir)) {
mkdir($save_dir, 0777, true);
}
if (file_exists($thumb_file)) {
$image = new OC_Image($thumb_file);
} else {
$image_path = OC_Filesystem::getLocalFile($image_path);
if (!file_exists($image_path)) {
return null;
}
$image = new OC_Image($image_path);
if ($image->valid()) {
$image->centerCrop(200);
$image->fixOrientation();
$image->save($thumb_file);
}
}
if ($image->valid()) {
return $image;
} else {
$image->destroy();
}
return null;
}
示例10: 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;
}
示例11: getNoCoverThumbnail
/**
* Generates a default image when the file has no cover
*
* @return bool|\OCP\IImage false if the default image is missing or invalid
*/
private function getNoCoverThumbnail()
{
$icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png';
if (!file_exists($icon)) {
return false;
}
$image = new \OC_Image();
$image->loadFromFile($icon);
return $image->valid() ? $image : false;
}
示例12: testValid
public function testValid()
{
$img = new \OC_Image(OC::$SERVERROOT . '/tests/data/testimage.png');
$this->assertTrue($img->valid());
$text = base64_encode("Lorem ipsum dolor sir amet …");
$img = new \OC_Image($text);
$this->assertFalse($img->valid());
$img = new \OC_Image(null);
$this->assertFalse($img->valid());
}
示例13: handleGetAlbumThumbnail
function handleGetAlbumThumbnail($token, $albumname)
{
$owner = OC_Gallery_Sharing::getTokenOwner($token);
$file = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/gallery/' . $albumname . '.png';
$image = new OC_Image($file);
if ($image->valid()) {
$image->centerCrop();
$image->resize(200);
$image->fixOrientation();
OCP\Response::enableCaching(3600 * 24);
// 24 hour
$image->show();
}
}
示例14: handleGetAlbumThumbnail
function handleGetAlbumThumbnail($token, $albumname)
{
$owner = OC_Gallery_Sharing::getTokenOwner($token);
$view = OCP\Files::getStorage('gallery');
$file = $view->fopen($albumname . '.png', 'r');
$image = new OC_Image($file);
if ($image->valid()) {
$image->centerCrop();
$image->resize(200);
$image->fixOrientation();
OCP\Response::enableCaching(3600 * 24);
// 24 hour
$image->show();
}
}
示例15: getThumbnail
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
//get fileinfo
$fileInfo = $fileview->getFileInfo($path);
if (!$fileInfo) {
return false;
}
$image = new \OC_Image();
//check if file is encrypted
if ($fileInfo['encrypted'] === true) {
$image->loadFromData(stream_get_contents($fileview->fopen($path, 'r')));
} else {
$image->loadFromFile($fileview->getLocalFile($path));
}
return $image->valid() ? $image : false;
}