summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-07-15 18:04:27 -0100
committerMaxence Lange <maxence@artificial-owl.com>2019-07-15 18:04:27 -0100
commit31a5b21a6ea85d28903e90ca05f4b3e5922cd053 (patch)
tree464907f9028b1d0f2b0d222ff6e61324ec497def /lib
parentad7c3770a33b9d9a451d984fcaaf34d404a5c4d5 (diff)
resize attachments
Signed-off-by: Maxence Lange <maxence@artificial-owl.com> cleaning Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Service/CacheDocumentService.php20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Service/CacheDocumentService.php b/lib/Service/CacheDocumentService.php
index 84aa32a2..567c934d 100644
--- a/lib/Service/CacheDocumentService.php
+++ b/lib/Service/CacheDocumentService.php
@@ -35,6 +35,8 @@ use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TStringTools;
use Exception;
+use Gumlet\ImageResize;
+use Gumlet\ImageResizeException;
use OCA\Social\Exceptions\CacheContentException;
use OCA\Social\Exceptions\CacheContentMimeTypeException;
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
@@ -131,6 +133,7 @@ class CacheDocumentService {
fclose($tmpFile);
$this->filterMimeTypes($mime);
+ $this->resizeImage($content);
$cache = $folder->newFile($filename);
$cache->putContent($content);
@@ -160,6 +163,23 @@ class CacheDocumentService {
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
*