Skip to content

Commit

Permalink
Changes in the configuration behavior. New parameter added.
Browse files Browse the repository at this point in the history
  • Loading branch information
todstoychev committed Nov 11, 2015
2 parents 4b67710 + bd4b2c5 commit 8740a3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ public function upload(UploadedFile $uploadedFile, $context)
try {
$fileName = $this->uploadImage($uploadedFile, $context);

$this->processImage($context, $fileName);

return $fileName;
return $this->processImage($context, $fileName);
} catch (\Exception $e) {
$this->getDeleteImageHandler()->deleteImage($context, $fileName);

Expand Down Expand Up @@ -279,6 +277,8 @@ protected function uploadImage(UploadedFile $uploadedFile, $context)
*
* @param string $context
* @param string $fileName
*
* @return string
*/
protected function processImage($context, $fileName)
{
Expand All @@ -300,12 +300,14 @@ protected function processImage($context, $fileName)
// Perform operation and save the image
$operation->doAction();
$path = public_path($config['uploads_path'] . '/' . $context . '/' . $sizeName . '/' . $fileName);
$path = preg_replace('/\.[a-z]{3,4}$/', $values['format'], $path);
$path = preg_replace('/\.[a-z]{3,4}$/', $config['output_format'][$context], $path);
$imageCopy->save($path);

// Delete existing instance
unset($imageCopy);
}

return preg_replace('/\.[a-z]{3,4}$/', $config['output_format'][$context], $fileName);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,27 @@
],
],

// Context output format
'output_format' => [
'default' => '.jpg',
],

// Context settings
'default' => [
'small' => [
'width' => 32,
'height' => 32,
'operation' => 'resize-crop',
'format' => '.jpg',
],
'medium' => [
'width' => 100,
'height' => 100,
'operation' => 'resize-crop',
'format' => '.jpg',
],
'large' => [
'width' => 200,
'height' => 200,
'operation' => 'resize-crop',
'format' => '.jpg',
],
],
];

0 comments on commit 8740a3f

Please sign in to comment.