Created
February 23, 2020 14:55
-
-
Save bugzbrown/2fadb8b460f3217a54992467b310528e to your computer and use it in GitHub Desktop.
Resize Image on Save octoberCMS
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
use October\Rain\Database\Attach\Resizer; | |
class ClassName extends Model{ | |
public $attachOne = [ | |
'img' => 'System\Models\File', | |
]; | |
public function afterSave(){ | |
$imgPath = $this->img->getLocalPath(); | |
$width = 800; | |
$height = 800; | |
$options = []; // or ['mode' => 'crop'] | |
Resizer::open($imgPath) | |
->resize($width, $height, $options) | |
->save($imgPath); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can be used in any model of octoberCMS that has an image - it is used to ensure that the file is of a maximum size (width and height).