symfonyckeditorelfinder

Symfony / CKEditor / Elfinder : is it possible to convert automatically uploaded image png to jpg?


From Symfony 5, I installed and configured the CKEditor buundle and attach it to the Elfinder bundle.

enter image description here

enter image description here

All works perfectly. Now, for increase the users experiences, I would like convert automatically any png file updated via elfinder to jpg file (for save disk space usage ;) )

Despite my researches, I can't find if there is a CKEditor and/or Elfinder way for upload image. Nothing in the documentation. I also look the result of the php bin/console config:dump-reference fm_elfinder command, but I don't find anything about a conversion...

Does that mean there isn't a quick/provided way for do what I'm looking for ?

Thanks for any help :)


Solution

  • Are you sure that it will increase the users experiences to convert their png to a jpg image? I don't think so, you will loose a lot of functionalities of png (transparency, color protection, etc.). Do not forget that png image can be compressed too!

    If you are sure that, in your case, it will increase the users experience, this bundle does natively not do it. You'll have to code. I saw two solutions:

    Solution1: FMElFinderBundle comes with a plugin to resize image. You could perhaps have a look on it to create a new specification which will transform png into jpeg instead of resize it.

    Solution2: FMElFinderBundle use the FileSystem Symfony component to store image. This bundle allows developers to change this component (If you want to replace it by an Amazon service as example). You could create your own component by overriding the Symfony filesystem. Just replace the dumpfile or the copy methods. If file is a png, you call the gd2 library to convert it.