Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizing original image on upload #31

Open
chocolata opened this issue Mar 16, 2018 · 4 comments
Open

Resizing original image on upload #31

chocolata opened this issue Mar 16, 2018 · 4 comments

Comments

@chocolata
Copy link
Collaborator

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.

@chocolata chocolata changed the title Resizing on upload Resizing original image on upload Mar 16, 2018
@meysammahfouzi
Copy link

@toughdeveloper This is my question too. Please advise.

@meysammahfouzi
Copy link

@maartenmachiels Have you been able to get it working?

@chocolata
Copy link
Collaborator Author

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

@matteotrubini
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants