Commits

Christoffer Niska committed 68cf0c3

added support for customizing folder names

  • Participants
  • Parent commits 3d3a977

Comments (0)

Files changed (4)

File components/ImgManager.php

-<?php
+<?php
 /**
  * Image manager class file.
  * @author Christoffer Niska <ChristofferNiska@gmail.com>
 	 */
 	public $imagePath='files/images/';
 	/**
+	 * @var string the name of the original directory.
+	 */
+	public $originalDir='original';
+	/**
+	 * @var string the name of the version directory.
+	 */
+	public $versionDir='versions';
+	/**
 	 * @var array the image versions.
 	 */
 	public $versions=array();
 
 			$path=$this->resolveImagePath($image);
 
-			if(!file_exists($path))
-				if(!$this->createDirectory($path))
-					throw new ImgException(Img::t('error','Failed to save image! Directory could not be created.'));
+			if(!file_exists($path) && !$this->createDirectory($path))
+				throw new ImgException(Img::t('error','Failed to save image! Directory could not be created.'));
 
 			$path.=$this->resolveFileName($image);
 
 				$thumb->applyOptions($options);
 				$path=$this->resolveImageVersionPath($image,$version);
 
-				if(!file_exists($path))
-					if(!$this->createDirectory($path))
-						throw new ImgException(Img::t('error','Failed to create version! Directory could not be created.'));
+				if(!file_exists($path) && !$this->createDirectory($path))
+					throw new ImgException(Img::t('error','Failed to create version! Directory could not be created.'));
 
 				$path.=$fileName;
 
 		if($this->_originalBasePath!==null)
 			$path.=$this->_originalBasePath;
 		else
-			$path.=$this->_originalBasePath = $this->getImagePath().'original/';
+			$path.=$this->_originalBasePath = $this->getImagePath().$this->originalDir.'/';
 
 		return $path;
 	}
 		if($this->_versionBasePath!==null)
 			$path.=$this->_versionBasePath;
 		else
-			$path.=$this->_versionBasePath = $this->getImagePath().'versions/';
+			$path.=$this->_versionBasePath = $this->getImagePath().$this->versionDir.'/';
 
 		return $path;
 	}

File components/ImgThumb.php

  */
 class ImgThumb extends CComponent
 {
+	const TYPE_GIF = 'GIF';
+	const TYPE_JPG = 'JPG';
+	const TYPE_PNG = 'PNG';
+
 	/**
-	 * @property ThumbBase the PhpThumb object.
+	 * @var ThumbBase the PhpThumb object.
 	 */
 	private $_thumb;
 

File controllers/DefaultController.php

 	 * @param string $version the name of the image version.
 	 * @throws CHttpException if the requested version is not defined.
 	 */
-	public function actionCreate($id,$version)
+	public function actionCreate($id, $version)
 	{
 		$versions=Yii::app()->image->versions;
 		if(isset($versions[$version]))
 		else
 			throw new CHttpException(404,Img::t('error','Failed to create image! Version is unknown.'));
 	}
+
+	/**
+	 * Creates and renders a new version of a specific image.
+	 * @param string $filename the image file name.
+	 */
+	public function actionCreateFromFilename($filename)
+	{
+		$thumb = Yii::app()->image->createVersionFromFilename($filename);
+		$thumb->render();
+	}
 }

File data/schema.sql

-DROP TABLE IF EXISTS `Image`;
+DROP TABLE IF EXISTS `image`;
 
-CREATE TABLE `Image` (
+CREATE TABLE `image` (
 	`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 	`name` varchar(255) NOT NULL,
+	`path` varchar(255) NOT NULL,
 	`extension` varchar(255) NOT NULL,
 	`filename` varchar(255) NOT NULL,
 	`byteSize` int(10) unsigned NOT NULL,