1. Christoffer Niska
  2. yii-img
  3. Issues
Issue #3 new

Suggestion to onDemandImage generation

Anonymous created an issue


thank you for that great Yii Extension!

As I had several problems with the Installation I'd like to share my modifications.

1) the installtion does not work on sqlite database, at least I had to create the table by my own

2) SQLITE has problems with NOW(), i've modified you code as follows /* * Saves a new image. * Premkumar Subramanian CUploadedFile $file the uploaded image. * Premkumar Subramanian string $name the image name. Available since 1.2.0 * Premkumar Subramanian string $path the path to save the file to. Available since 1.2.1. * PROGRAMMER Image the image record. * @throws ImageException if saving the image record or file fails. / public function save($file,$name=null,$path=null) { $trx=Yii::app()->db->beginTransaction();

        $image=new Image();
        $image->created=date('c'); // fix for sqlite

3) I modified the ImgManager to create the images on demand without using htaccess file. As there the file extensions hardcoded in the htaccess file there might be a problem when uploading files (eg. jpeg). Here is my code: /* * Returns the URL for a specific image. * Premkumar Subramanian string $id the image id. * Premkumar Subramanian string $version the name of the image version. * Premkumar Subramanian boolean $absolute whether or not to get an absolute URL. * PROGRAMMER string the URL. * @throws CException if the version is not defined. / public function getURL($id,$version,$absolute=false) { if(isset($this->versions[$version])) { $image=$this->loadModel($id);

        // create images on demand
        $imagePath = $this->resolveImageVersionPath($image,$version).$this->resolveFileName($image);
        if(!file_exists($imagePath)) {

        return Yii::app()->request->getBaseUrl($absolute).'/'.$path;
        throw new ImgException(Img::t('error','Failed to get image URL! Version is unknown.'));

regards Roland

Comments (0)

  1. Log in to comment