Issue #3 new

Suggestion to onDemandImage generation

Anonymous created an issue

Hi,

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();

    try
    {
        $image=new Image();
        $image->extension=strtolower($file->getExtensionName());
        $image->filename=$file->getName();
        $image->byteSize=$file->getSize();
        $image->mimeType=$file->getType();
        $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)) {
            $this->createVersion($id,$version);
        }

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

regards Roland

Comments (0)

  1. Log in to comment