PawelC
PawelC

Reputation: 1226

Symfony - resize image after upload

I have the following problem, uploads a file using symfony, it is moved with the original resolution and extension. And now I would like to create a second file, which is a copy of the first one but with a resolution of 320px x 60px and that it should be in the name, ie how the original file has the name: my_images.png I would like the copy to be named my_images_320x60.png

After correct upload, my picture is available at http: //localhost/uploads/i/my_images.png

My upload looks like this:

$logoFile = $this->getValidatorParameter('logo_file');
$storage = $this->get('file.event.storage');
$file = $storage->upload($logoFile->getValue());

Anyone have any idea how to do it? The image is copied, I have a path to it, but I can not change its resolution and name :(

Upvotes: 0

Views: 6468

Answers (1)

intervention/image works very well with Symfony, for example:

// open an image file
$img = Image::make('public/foo.jpg');

// resize image instance
$img->resize(320, 240);

// save image in desired format
$img->save('public/bar.jpg');

Upvotes: 6

Related Questions