Symfony2 : Resizing uploaded images

2019-03-31 06:13发布

问题:

Is there any way to resize pictures while uploading them in Symfony2 ?

The ImagineAvalancheBundle only allows to resize images to thumbnails when retrieving them, which is not really performant to me.

Besides, the UploadedFile object retreived when posting data doesn't seems to have resizing methods...

Any Idea ?

回答1:

I had the same problem you are asking for.

The main issue is that the bundle resizes and/or crops the images directly. So that can take a lot of time with big images and if many images are expected per page.

So I've fix this issue by calling directly after imageupload the resize() function to the image. Hence, I save (copy) the resized image to the filesystem at the server. Obviously I store the path of the image into the database to can load it directly if needed.

I tried the included memcache of the imageresize bundle but in my case it doesn't work.



回答2:

I had the same problem for a project that i'm actually developing. I searched a lot on the net and found nothing realy performant and also easy to use for non-tech people.

I created a bundle to be able to upload with jquery file upload and crop with jcrop with some other functions.

ComurImageBundle



回答3:

What is exactly your goal ? Resize and crop ? Other ?

I don't understand why you say that the bundle resize to thumbnail only as you can define precisely your resize preset through config :

  # app/config/config.yml

    avalanche_imagine:
        filters:
            my_thumb:
                type:    thumbnail
                options: { size: [120, 90], mode: outbound }