Skip to content

Commit

Permalink
Resolved #15, the real name in the cache name
Browse files Browse the repository at this point in the history
  • Loading branch information
dusta authored Dec 6, 2018
1 parent 75f136a commit 5a14f41
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,33 @@ public function cache($adapter, $originalImage, $default = false)
$output['stylist'] = $this->stylist;
$output['size'] = $this->size;

$ext = substr($originalImage, strrpos($originalImage, "."));
/**
* Get extension
*/
$ext = pathinfo($originalImage, PATHINFO_EXTENSION);

$stylist = $output['stylist'];

if (isset($output['size']) and !empty($output['size'])) {
$stylist .= '-' . $this->size;
}

/**
* Create Static cache path based on $originalImage
*/
$cachePath = [];
$cachePath[0] = substr(md5($originalImage), 0, 6);
$cachePath[1] = substr(md5($originalImage), 6, 6);
$cachePath[2] = substr(md5($stylist . '+' . $originalImage), 0, 6);
$cachePath[3] = $stylist;

$cache = $cachePath[0] . '-' . $cachePath[1] . '-' . $cachePath[2] . '-' . $cachePath[3] . $ext;
$cache = str_replace(basename($originalImage, $ext) . $ext, $cache, $originalImage);
$basename = basename($originalImage, '.' . $ext);
if (!empty($basename)) {
$basename = $basename . '-';
}
$cache = $basename . $cachePath[0] . '-' . $cachePath[1] . '-' . $cachePath[2] . '-' . $cachePath[3] . '.' . $ext;

$cacheAdapter = 'cache://' . $cache;

$sourceAdapter = $adapter . '://' . $originalImage;

$has = $this->manager->has($cacheAdapter);
Expand Down Expand Up @@ -238,6 +246,7 @@ protected function getStylist($stylist = 'orginal')
public function get($adapter = 'local')
{
$data = $this->cache($adapter, $this->orginalImage);

if (!empty($this->storage->getDriver())) {
$get = $this->storage->getDriver()
->get($adapter, $this->orginalImage, $data['cache']);
Expand Down

0 comments on commit 5a14f41

Please sign in to comment.