-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Watermark preview, Job Download
- Loading branch information
Showing
8 changed files
with
67,542 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use App\Job; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Storage; | ||
use Intervention\Image\Facades\Image; | ||
|
||
class ImageModifier | ||
{ | ||
/** | ||
* @var Job | ||
*/ | ||
public $job; | ||
|
||
/** | ||
* Files to process | ||
* | ||
* @var array|Collection | ||
*/ | ||
public $files = []; | ||
|
||
/** | ||
* File processing preset | ||
* | ||
* @var Preset | ||
*/ | ||
public $preset; | ||
|
||
/** | ||
* Preset options | ||
* | ||
* @var mixed | ||
*/ | ||
public $options; | ||
|
||
public function __construct(Job $job) | ||
{ | ||
$this->job = $job; | ||
$this->files = $job->files; | ||
$this->preset = $job->preset; | ||
$this->options = json_decode($this->preset->options); | ||
} | ||
|
||
public function process() | ||
{ | ||
$job_directory = $this->job->getJobDirectory(); | ||
$output_directory = $this->job->getOutputDirectory(); | ||
|
||
if (empty($this->options->resolutions)) { | ||
return [ | ||
'status' => false, | ||
'message' => 'No resolutions specified for output.' | ||
]; | ||
} | ||
|
||
# If the output directory exists, delete it. | ||
if (Storage::exists($output_directory)) { | ||
Storage::deleteDirectory($output_directory); | ||
} | ||
|
||
Storage::makeDirectory($output_directory); | ||
|
||
# make directories for different resolutions | ||
$resolutionDirectories = []; | ||
foreach ($this->options->resolutions as $resolution) { | ||
if (!empty($resolution->width) && !empty($resolution->height)) { | ||
$resolutionDirectory = (int)$resolution->width . 'x' . (int)$resolution->height; | ||
$resOutputDirectory = $output_directory . DIRECTORY_SEPARATOR . $resolutionDirectory; | ||
if (Storage::makeDirectory($resOutputDirectory)) { | ||
$resolutionDirectories[] = $resOutputDirectory; | ||
} | ||
} | ||
} | ||
|
||
// process each image for different resolutions | ||
$this->files->each(function ($file, $index) use ($output_directory) { | ||
foreach ($this->options->resolutions as $resolution) { | ||
if (!empty($resolution->width) && !empty($resolution->height)) { | ||
$resolutionDirectory = (int)$resolution->width . 'x' . (int)$resolution->height; | ||
$resOutputDirectory = $output_directory . DIRECTORY_SEPARATOR . $resolutionDirectory; | ||
|
||
echo storage_path($file->full_path); | ||
$image = Image::make(storage_path($file->full_path)) | ||
->resize($resolution->width, $resolution->height); | ||
|
||
// later add watermark. | ||
$filename = $file->name; | ||
if ($this->options->filename_prefix) { | ||
$filename = sprintf("%s%04d", $this->options->filename_prefix, $index); | ||
} | ||
|
||
$image->save(storage_path($resOutputDirectory . DIRECTORY_SEPARATOR . $filename)); | ||
} | ||
} | ||
}); | ||
// store the images in their respective folders | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters