matt-pawley / oc-imageresizer-plugin

October CMS Plugin to resize and compress images
https://octobercms.com/plugin/toughdeveloper-imageresizer
MIT License
46 stars 39 forks source link

Resizing original image on upload #31

Open chocolata opened 6 years ago

chocolata commented 6 years ago

Hi,

Thanks for your fantastic plugin. I'm so glad it's out here, because it works great.

In my project I have a standard form in which people can upload 5 images. These images are stored as file attachment in System\Models\File. Right now I'm uploading the images in their original uncompressed form and resize them when they appear on the frontend, using the twig filter {{ '/path/to/image.jpg' | resize(250, 100) }}. This works great, but I'd like to compress the original images as well.

A nice rule I'm having in my head is forcing images not to exceed 1000 by 1000 pixels, and also running them by TinyPNG. This way, I'd save a lot of disk space, because I'm seeing images of 10MB+ in this project.

I've noticed we can use your plugin in PHP too. Is it possible to save the compressed image and to replace the original? Something like:

use ToughDeveloper\ImageResizer\Classes\Image;
use ThirdPartyDeveloper\CarManager\Models\Car;

// Create a new instance of car based on user input
$car= new Car();
$car->name = Input::get('car_name');
$car->save();

// Compress image
$image = new Image(Input::file('car_image'));
$image->resize(1000, 1000);

// Attach compressed image
 $car->images()->create(['data' =>$image]);

Would something like this be possible? I was experimenting with another plugin, but kept running into problems.

A second part of the question is: would we be able to do something like the linked plugin, where we compress images as soon as they appear in the media library?

What are your thoughts? Thanks in advance.

meysammahfouzi commented 6 years ago

@toughdeveloper This is my question too. Please advise.

meysammahfouzi commented 6 years ago

@maartenmachiels Have you been able to get it working?

chocolata commented 6 years ago

Hi, unfortunately no. I managed to get it working via another plugin: https://github.com/PopcornPHP/oc-image-compress-plugin

matteotrubini commented 4 years ago

This plugin is being migrated to core (see #55), so we are trying to figure out what issues are still relevant to invite to reopen them in core.

Issues that will remain inactive in next 30 days will be closed.