Skip to content

Commit

Permalink
Improved someline-image to support always store in original files
Browse files Browse the repository at this point in the history
  • Loading branch information
libern committed Oct 27, 2017
1 parent 24073bb commit f5f87ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Someline/Image/SomelineImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ private function largeImageQuality()
return (int)$this->getConfig('large_image_quality', 65);
}

/**
* @return boolean
*/
private function isAlwaysOriginal()
{
return (boolean)$this->getConfig('always_original', true);
}

/**
* @param UploadedFile $file
* @param string $additionValidatorRule
Expand Down Expand Up @@ -111,6 +119,7 @@ public function storeImageFromPath($path_with_name, $file_extension = null, $isA
$originHeight = $image->getHeight();
$image_file_size_kb = $file_origin_size / 1024;
$is_allowed_animated_gif = $is_animated_gif;
$isStoreOriginImage = $this->isAlwaysOriginal();

// save as jpg
$default_file_extension = 'jpg';
Expand All @@ -121,6 +130,9 @@ public function storeImageFromPath($path_with_name, $file_extension = null, $isA
if ($isStorePNG && $is_file_png) {
$default_file_extension = 'png';
}
if ($isStoreOriginImage) {
$default_file_extension = $file_extension;
}
$storage_path = $this->storagePath();
$file_sha1 = sha1_file($path_with_name);
$final_file_sha1 = null;
Expand Down Expand Up @@ -152,7 +164,7 @@ public function storeImageFromPath($path_with_name, $file_extension = null, $isA
}

if (!$isExists) {
if (($isAllowGIF && $is_allowed_animated_gif) || ($isStorePNG && $is_file_png)) {
if (($isStoreOriginImage) || ($isAllowGIF && $is_allowed_animated_gif) || ($isStorePNG && $is_file_png)) {
if (File::copy($path_with_name, $final_path_with_name)) {
@chmod($final_path_with_name, 0666 & ~umask());
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

return array(

/**
* Always store uploaded files without modifications
*/
'always_original' => true,

/**
* Default image store quality
* default: 75
Expand Down

0 comments on commit f5f87ef

Please sign in to comment.