diff options
Diffstat (limited to 'protected/components/VereinImageFunctions.php')
| -rw-r--r-- | protected/components/VereinImageFunctions.php | 45 |
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 |
