This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Is it possible or I should use some external library such as http://image.intervention.io/getting_started/introduction?
Last updated
I'm guessing that you could override the destination path in your plugin. Here's an example of how Laravel uploads files:
http://maxoffsky.com/code-blog/uploading-files-in-laravel-4/
But what is the point of this method? It's helpful for versioning and such that everything is kept in the /uploads/ folder, and you can always link to those just as well as assets. That helps keep the site structure organized.
Oh I'm sorry. I completely skimmed over the image manipulation part. As far as I know, Laravel doesn't include one by default. So you're probably correct about needing the Intervention or some other third-party library (such as GD).
Yes I needed the same. I edited the composer.json file for intervention like this:
"require": {
"php": ">=5.4",
"laravel/framework": "4.2.*",
"october/system": "~1.0",
"october/backend": "~1.0",
"october/cms": "~1.0",
"october/rain": "~1.0",
"intervention/image": "2.*"
},
but when I try to update via command line with "composer update" it says "killed" after some time.
To update composer, I need to make a swap file on the root of my server. Simply composer update with the new json file fails because of memory.
On the other hand, after completing composer update, I added two lines to app/config/app.php as indicated in the laravel intallation documentation at the site of intevention. http://image.intervention.io/getting_started/installation
After you have installed Intervention Image, open your Laravel config file config/app.php and add the following lines.
Instead of this, october users should go to the "app/config/app.php" of the october root. In the $providers array add the service providers for this package.
'Intervention\Image\ImageServiceProvider'
Add the facade of this package to the $aliases array.
'Image' => 'Intervention\Image\Facades\Image'
Is there a way to catch the uploaded image to resize?
Something like onUpload
event to resize the original uploaded image. I need that to prevent oversize of products images. I actually use the afterSave
event, but the newest uploaded images are not loaded on the event.
public function afterSave() {
if($this->images->count()) {
/** @var DashboardProperty $settings */
$settings = DashboardProperty::instance();
foreach($this->images as $image) {
/** @var \Intervention\Image\Image $img */
$img = Image::make($image->getDiskPath());
$imgHeight = $img->height();
$imgWidth = $img->width();
$width = null;
$height = null;
if($imgWidth > $settings->max_image_width || $imgHeight > $settings->max_image_height){
if ($imgWidth >= $imgHeight) {
$width = $settings->max_image_width;
} else {
$height = $settings->max_image_height;
}
$img->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->save();
}
}
}
}
Any help on it? Thanks and sorry my english.
I was able to get something working using the Model's listener, and without requiring Intervention\Image:
use October\Rain\Database\Attach\Resizer;
...
EngineeredWood::saving( function($wood)
{
if($wood->main_image)
{
$path = base_path() . MediaLibrary::instance()->getPathUrl('/');
$file = "{$path}/$wood->main_image";
$thumbFile = "{$file}-600.jpg";
if (!file_exists($thumbFile))
{
Resizer::open($file)
->resize(600, 600, 'exact')
->save($thumbFile);
}
}
});
Last updated
1-7 of 7