Commit 7e78b764 authored by Nicolas Widart's avatar Nicolas Widart

Adding force create option

parent c5b0ebec
...@@ -31,25 +31,28 @@ class Imagy ...@@ -31,25 +31,28 @@ class Imagy
$this->imageFactory = $imageFactory; $this->imageFactory = $imageFactory;
} }
public function get($path, $thumbnail) public function get($path, $thumbnail, $forceCreate = false)
{ {
$filename = '/assets/media/' . $this->newFilename($path, $thumbnail); $filename = '/assets/media/' . $this->newFilename($path, $thumbnail);
try { try {
$this->finder->get(public_path(). $filename); $this->finder->get(public_path(). $filename);
return $filename; if (!$forceCreate) {
return $filename;
}
} catch (FileNotFoundException $e) { } catch (FileNotFoundException $e) {
$image = $this->image->make(public_path() . $path); // Continue execution
}
$image = $this->image->make(public_path() . $path);
foreach ($this->config->get("media::thumbnails.{$thumbnail}") as $manipulation => $options) { foreach ($this->config->get("media::thumbnails.{$thumbnail}") as $manipulation => $options) {
$image = $this->imageFactory->make($manipulation)->handle($image, $options); $image = $this->imageFactory->make($manipulation)->handle($image, $options);
} }
$image = $image->encode(pathinfo($path, PATHINFO_EXTENSION)); $image = $image->encode(pathinfo($path, PATHINFO_EXTENSION));
$this->finder->put(public_path() . $filename, $image); $this->finder->put(public_path() . $filename, $image);
return $filename; return $filename;
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment