Gregwar / Image

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

Absolute and relative path (web root) #111

Closed Bogdaan closed 8 years ago

Bogdaan commented 8 years ago

Hi, i have some issues with absolute paths

for example i have:

(filesystem) 
|- app - application logi
|- www - web root dir
|-- index.php - single php file
|-- cache/ - image cache dir

When i use this code:

$img
->setCacheDir( $wwwDir.'/cache' )
->html();

I found full path like:

(filesystem dirs)/../www/cache/e/8/d/4/5/e8d452e74e32d36c1ef10c4bc3d17ece1c695235.jpg

But actual (available) web path is:

/cache/e/8/d/4/5/e8d452e74e32d36c1ef10c4bc3d17ece1c695235.jpg

Therefore it is necessary to use own parent class with custum constructor and getFilename.

// set $this->wwwDir in __constructor
protected function getFilename($filename) 
{
   return str_replace($this->wwwDir, '', $filename);
}

May be this functionality would be useful "out the box"?

Gregwar commented 8 years ago

Hello, this is the point of setActualCacheDir which is not documented here You can do a PR that explains this if you want :-)

Gregwar commented 8 years ago

See https://github.com/Gregwar/Cache#cache-directory-and-actual-cache-directory

Bogdaan commented 8 years ago

@Gregwar thanks