# Plugin idea: Image optimization with WebP

**URL:** <https://meta.discourse.org/t/plugin-idea-image-optimization-with-webp/36470>\
**Category:** Feature\
**Created:** [December 9, 2015, 10:05am UTC](https://meta.discourse.org/t/plugin-idea-image-optimization-with-webp/36470 "2015-12-09T10:05:48Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![aryanraj](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@aryanraj](https://meta.discourse.org/u/aryanraj)\
**Post date:** [March 15, 2016, 7:46pm UTC](https://meta.discourse.org/t/plugin-idea-image-optimization-with-webp/36470/6 "2016-03-15T19:46:10Z")

</div>

In order to get familiarised with the discourse codebase was trying to add conversion of gif to video format and storing it.

Firstly here is what I understood from the code and correct me if I am wrong.

1. When a file is uploaded, it triggers UploadsController#create
2. UploadsController makes some optimizations and then call [Upload.create\_for](https://github.com/discourse/discourse/blob/master/app/controllers/uploads_controller.rb#L93)
3. Upload model creates a record and sends an object back to UploadsController.
4. UploadsController sends back the data as json to Ember app.
5. Ember app [checks for link to be an image](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/utilities.js#L261) and wraps it around img tag.

What I thought of doing:-

1. I chose to use ffmpeg to convert gif to mp4 video and then insert the mp4 video to the uploads record.
2. I have added a script to convert gif to mp4 video [here](https://github.com/discourse/discourse/blob/master/app/models/upload.rb#L119) in upload model.
3. But there was an error message saying that format was not supported.
4. I figured out that it was because of [this validator check](https://github.com/discourse/discourse/blob/master/app/models/upload.rb#L22) and if I add an exception for mp4 extension everything works, but people are then able to upload mp4 videos.
5. I could have added the script in OptimizedImage model, but it looks like it is used mainly for storing thumbnails of the images.  
Note: -With the above implementation we will be losing the original gif image.

Could somebody tell me if I have understood the flow correctly and suggest me changes in my implementation?

---

_[View the full topic](https://meta.discourse.org/t/plugin-idea-image-optimization-with-webp/36470)._
