summaryrefslogtreecommitdiff
path: root/protected/components/VereinImageFunctions.php
diff options
context:
space:
mode:
authorTristan Zur <tzur@ccwn.org>2012-05-18 11:31:14 +0200
committerTristan Zur <tzur@ccwn.org>2012-05-18 11:31:14 +0200
commitbb5de528c46a6acc56c9e856caae5f9999319d62 (patch)
treef9c1772868663342b242a2eaa8fa71baafc2eefc /protected/components/VereinImageFunctions.php
parent3cb7fbfceae978d2b87ae976bf4536c3461bb868 (diff)
- Dateiupload in eigene Klasse ausgelagert -> Upload wird immer gleich
durchgeführt. - Extension SimpleImage hinzugefügt -> Bildgrößen werden nun auf eine konfigurierbare Maximalbreite und Maximalhöhe verkleinert
Diffstat (limited to 'protected/components/VereinImageFunctions.php')
-rw-r--r--protected/components/VereinImageFunctions.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/protected/components/VereinImageFunctions.php b/protected/components/VereinImageFunctions.php
new file mode 100644
index 0000000..477e767
--- /dev/null
+++ b/protected/components/VereinImageFunctions.php
@@ -0,0 +1,45 @@
+<?php
+class VereinImageFunctions {
+ const BASE_PATH = 'images/uploaded/';
+
+ public static function resizeAndSave(CUploadedFile $uploadedImage, $vereinSlug) {
+ $filename = VereinImageFunctions::save($uploadedImage, $vereinSlug);
+ if (null !== $filename) {
+ VereinImageFunctions::resize($filename);
+ }
+
+ return $filename;
+ }
+
+ public static function save(CUploadedFile $uploadedImage, $vereinSlug) {
+ $filename = VereinImageFunctions::createFilename($uploadedImage->getName(), $vereinSlug);
+ if ($uploadedImage->saveAs($filename)) {
+ return $filename;
+ } else {
+ return null;
+ }
+ }
+
+ public static function resize($filename) {
+ $image = Yii::app()->simpleImage->load($filename);
+
+ if ($image->getWidth() > Yii::app()->params['logo_width']) {
+ $image->resizeToWidth(Yii::app()->params['logo_width']);
+ }
+
+ if ($image->getHeight() > Yii::app()->params['logo_height']) {
+ $image->resizeToHeight(Yii::app()->params['logo_height']);
+ }
+ $image->save($filename);
+ }
+
+ private static function createFilename($uploadedName, $vereinSlug) {
+ $suffix = VereinImageFunctions::getSuffix($uploadedName);
+ return VereinImageFunctions::BASE_PATH.time()."-".$vereinSlug.$suffix;
+ }
+
+ private static function getSuffix($name) {
+ return (null !== $name) ? substr($name, strrpos($name, '.')) : '';
+ }
+}
+?> \ No newline at end of file