Skip to content
This repository has been archived by the owner on Oct 31, 2020. It is now read-only.

Fixes #26 #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/Imageupload.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private function prepareConfigs()
$this->library = Config::get('imageupload.library', 'gd');
$this->quality = Config::get('imageupload.quality', 90);
$this->uploadpath = Config::get('imageupload.path', public_path('uploads/images'));
$this->s3_enabled = Config::get('imageupload.s3_enabled', false);
$this->newfilename = Config::get('imageupload.newfilename', 'original');
$this->dimensions = Config::get('imageupload.dimensions');
$this->suffix = Config::get('imageupload.suffix', true);
Expand Down Expand Up @@ -250,8 +251,11 @@ private function saveOriginalFile(UploadedFile $uploadedFile)

$image->save($targetFilepath, $this->quality);

// Save to s3
$s3_url = $this->saveToS3($image, $targetFilepath);
// Save to s3 if s3 is enabled
if(true === $this->s3_enabled) {
$s3_url = $this->saveToS3($image, $targetFilepath);
$this->results['s3_url'] = $s3_url;
}

$this->results['original_width'] = (int) $image->width();
$this->results['original_height'] = (int) $image->height();
Expand Down Expand Up @@ -317,21 +321,26 @@ private function resizeCropImage(UploadedFile $uploadedFile, $targetFilepath, $w

$image->save($targetFilepath, $this->quality);

// Save to s3
$s3_url = $this->saveToS3($image, $targetFilepath);

return [
$result = [
'path' => dirname($targetFilepath),
'dir' => $this->getRelativePath($targetFilepath),
'filename' => pathinfo($targetFilepath, PATHINFO_BASENAME),
'filepath' => $targetFilepath,
'filedir' => $this->getRelativePath($targetFilepath),
's3_url' => $s3_url,
'width' => (int) $image->width(),
'height' => (int) $image->height(),
'filesize' => (int) $image->filesize(),
'is_squared' => (bool) $squared,
];

// Save to s3
if(true === $this->s3_enabled) {
$s3_url = $this->saveToS3($image, $targetFilepath);
$result['s3_url'] = $s3_url;
}

return $result;

} catch (Exception $e) {
throw new ImageuploadException($e->getMessage());
}
Expand Down Expand Up @@ -416,8 +425,14 @@ private function saveToDatabase(Collection $collection)
$input[$key.'_'.$k] = $v;
}
}

return $model->firstOrCreate($input);

return $model->firstOrCreate([
'original_filesize' => $input['original_filesize'],
'original_width' => $input['original_filesize'],
'original_height' => $input['original_filesize'],
'path' => $input['path'],
'filename' => $input['filename']
], $input);
}

private function saveToS3($image, $targetFilepath) {
Expand Down