Gregwar / Image

A PHP library to handle images
MIT License
1k stars 191 forks source link

Set Cache Dir #39

Closed Surt closed 11 years ago

Surt commented 11 years ago

Hi, I was wondering if its possible to set the cache dir on the fly, without creating an instance. Actually, I don't know how to create a cache dir to activate it.

Gregwar commented 11 years ago

Hello, I'm not sure I understand your problem?

Surt commented 11 years ago

Hi @Gregwar . I was triying to set the cache folder, using:

/**
     * Change the caching directory
     */
    public function setCacheDir($cacheDir)
    {
        $this->cacheDir = $cacheDir;
    }

But I can't call it as static: Image::setCacheDir($afolder) since it says I'm calling a non static method.

Gregwar commented 11 years ago

The cache directory will be created automatically if you're worried about it, you just have to let enough permissions to your web server to do it

Surt commented 11 years ago

yep, but, where is created? It will be great to add the possibility to set the cache dir on the class, as a static.

Gregwar commented 11 years ago

You mean you're trying to change the default cache directory?

<?php

class MyApplicationSpecificImage extends Gregwar\Image\Image
{
    protected $cacheDir = 'my/custom/path/';
}
Surt commented 11 years ago

Yep, I will do that. Thanks @Gregwar ! keep the good work.

Surt commented 11 years ago

Sorry for bother, I was wondering if doing this, to get binary content of image from caché, is ok:

    public function guessGet($quality = 80){
        return $this->open($this->cacheFile('guess', $quality))->get();
    }
Gregwar commented 11 years ago

You'd better use file_get_contents, or readfile here

Surt commented 11 years ago

will do :)

Gregwar commented 11 years ago

Maybe I should add a flag to get the binary data when calling cacheFile, or a method to do that

Surt commented 11 years ago

It will be great to have it implemented.

Gregwar commented 11 years ago

You can now use cacheData() to do that

Surt commented 11 years ago

hahaaha, Great! Thanks a lot @Gregwar