kopia lustrzana https://github.com/nextcloud/social
resize attachments
Signed-off-by: Maxence Lange <maxence@artificial-owl.com> cleaning Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/626/head
rodzic
ad7c3770a3
commit
31a5b21a6e
|
@ -16,6 +16,7 @@
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"daita/my-small-php-tools": "dev-master",
|
"daita/my-small-php-tools": "dev-master",
|
||||||
|
"gumlet/php-image-resize": "1.9.*",
|
||||||
"friendica/json-ld": "^1.0"
|
"friendica/json-ld": "^1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "d711d18021f3044f1dbf97c6a423d2ac",
|
"content-hash": "f93a783c86bad53b0b8486db3fc61380",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "daita/my-small-php-tools",
|
"name": "daita/my-small-php-tools",
|
||||||
|
@ -12,12 +12,12 @@
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/daita/my-small-php-tools.git",
|
"url": "https://github.com/daita/my-small-php-tools.git",
|
||||||
"reference": "45a543b86ad93ea36845e5bc32ca03320b6cfa9c"
|
"reference": "6ba571ffa6bda6f32fcc6529a474ccc777eb1fb2"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/45a543b86ad93ea36845e5bc32ca03320b6cfa9c",
|
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/6ba571ffa6bda6f32fcc6529a474ccc777eb1fb2",
|
||||||
"reference": "45a543b86ad93ea36845e5bc32ca03320b6cfa9c",
|
"reference": "6ba571ffa6bda6f32fcc6529a474ccc777eb1fb2",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "My small PHP Tools",
|
"description": "My small PHP Tools",
|
||||||
"time": "2019-06-21T16:40:45+00:00"
|
"time": "2019-07-12T20:21:51+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "friendica/json-ld",
|
"name": "friendica/json-ld",
|
||||||
|
@ -85,6 +85,61 @@
|
||||||
"jsonld"
|
"jsonld"
|
||||||
],
|
],
|
||||||
"time": "2018-10-08T20:41:00+00:00"
|
"time": "2018-10-08T20:41:00+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "gumlet/php-image-resize",
|
||||||
|
"version": "1.9.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/gumlet/php-image-resize.git",
|
||||||
|
"reference": "06339a9c1b167acd58173db226f57957a6617547"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/gumlet/php-image-resize/zipball/06339a9c1b167acd58173db226f57957a6617547",
|
||||||
|
"reference": "06339a9c1b167acd58173db226f57957a6617547",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-fileinfo": "*",
|
||||||
|
"ext-gd": "*",
|
||||||
|
"php": ">=5.5.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"apigen/apigen": "^4.1",
|
||||||
|
"ext-exif": "*",
|
||||||
|
"ext-gd": "*",
|
||||||
|
"php-coveralls/php-coveralls": "^2.1",
|
||||||
|
"phpunit/phpunit": "^4.8"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-exif": "Auto-rotate jpeg files"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Gumlet\\": "lib/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Aditya Patadia",
|
||||||
|
"homepage": "http://aditya.patadia.org/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP class to re-size and scale images",
|
||||||
|
"homepage": "https://github.com/gumlet/php-image-resize",
|
||||||
|
"keywords": [
|
||||||
|
"image",
|
||||||
|
"php",
|
||||||
|
"resize",
|
||||||
|
"scale"
|
||||||
|
],
|
||||||
|
"time": "2019-01-01T13:53:00+00:00"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
|
|
@ -35,6 +35,8 @@ use daita\MySmallPhpTools\Model\Request;
|
||||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||||
use daita\MySmallPhpTools\Traits\TStringTools;
|
use daita\MySmallPhpTools\Traits\TStringTools;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Gumlet\ImageResize;
|
||||||
|
use Gumlet\ImageResizeException;
|
||||||
use OCA\Social\Exceptions\CacheContentException;
|
use OCA\Social\Exceptions\CacheContentException;
|
||||||
use OCA\Social\Exceptions\CacheContentMimeTypeException;
|
use OCA\Social\Exceptions\CacheContentMimeTypeException;
|
||||||
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
|
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
|
||||||
|
@ -131,6 +133,7 @@ class CacheDocumentService {
|
||||||
fclose($tmpFile);
|
fclose($tmpFile);
|
||||||
|
|
||||||
$this->filterMimeTypes($mime);
|
$this->filterMimeTypes($mime);
|
||||||
|
$this->resizeImage($content);
|
||||||
|
|
||||||
$cache = $folder->newFile($filename);
|
$cache = $folder->newFile($filename);
|
||||||
$cache->putContent($content);
|
$cache->putContent($content);
|
||||||
|
@ -160,6 +163,23 @@ class CacheDocumentService {
|
||||||
throw new CacheContentMimeTypeException();
|
throw new CacheContentMimeTypeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $content
|
||||||
|
*/
|
||||||
|
private function resizeImage(&$content) {
|
||||||
|
try {
|
||||||
|
$image = ImageResize::createFromString($content);
|
||||||
|
$image->quality_jpg = 100;
|
||||||
|
$image->quality_png = 9;
|
||||||
|
|
||||||
|
$image->resizeToBestFit(500, 300);
|
||||||
|
$content = $image->getImageAsString();
|
||||||
|
} catch (ImageResizeException $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
*
|
*
|
||||||
|
|
Ładowanie…
Reference in New Issue