This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Incremental
Hello, how is it possible to resize a picture in a backend plugin ? I tried :
$categ->image()->add($file);
$categ->image->getThumb(100, 100, ['mode' => 'auto']);
but it create a new thum file "thumb_50_100_100_0_0_auto.jpg" instead of resizing the original file.
How is it possible to resize the original file ? Thanks
daftspunky
You can hook into the beforeSave
event of the System\Models\File
model and adjust the image size there
Check out the documentation here: https://octobercms.com/docs/database/model#events
Incremental
Thanks daftspunk, I found another way which works fine, but don't know if it's right ?
use October\Rain\Database\Attach\Resizer;
$width = 100;
$height = 100;
$options = []; // or ['mode' => 'crop']
Resizer::open($categ->image->getLocalPath()) // create from real path
->resize($width, $height, $options)
->save($categ->image->getLocalPath());
1-3 of 3