# Uploaded animated GIFs of 4MB or larger appear very small

**URL:** https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107
**Category:** Support
**Created:** [7 april 2020 om 09:34 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107 "2020-04-07T09:34:16Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![Jack\_Vaughan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jack_vaughan/32/209286_2.png) [@Jack\_Vaughan](https://meta.discourse.org/u/Jack_Vaughan)
#### Post date: [7 april 2020 om 09:34 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/1 "2020-04-07T09:34:16Z")

</div>

Hi there guys, I just wondered why GIFs are so small when you upload them - even if you choose 100% as the size E.g

![2020-04-07 10.18.45](https://global.discourse-cdn.com/meta/original/3X/4/f/4f00c7baaff9336c4c5d01070c0e5b9e265c8699.gif)

---

<div class="post-metadata">

### Author: ![JimPas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jimpas/32/148179_2.png) [@JimPas](https://meta.discourse.org/u/JimPas)
#### Post date: [7 april 2020 om 10:33 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/2 "2020-04-07T10:33:51Z")

</div>

What is the size of the GIF you are uploading? The one below is 245x250 and uploads fine.

 ![babies12](https://global.discourse-cdn.com/meta/original/3X/a/8/a8ef415151db01b16a4dcfcf717fdf4c3601973c.gif)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [7 april 2020 om 22:42 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/3 "2020-04-07T22:42:39Z")

</div>

This looks like an error in speficically what you are choosing to upload? Can you describe it exactly, step by step, with examples?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [7 april 2020 om 23:50 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/4 "2020-04-07T23:50:53Z")

</div>

Here is a gif that triggers the issue. When I look at its properties on my computer, its type is set to ‘image/gif’. Its size is 10.4MB. It seems that Discourse is resizing its images. I am able to upload smaller gifs that I created in the same way without any display issues.

![featured_topic](https://global.discourse-cdn.com/meta/original/3X/0/d/0d0e62359ca7aeb79cfbda717f4e2b48848f4308.gif)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [8 april 2020 om 00:25 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/5 "2020-04-08T00:25:03Z")

</div>

So this is about GIFs that are normally too large to fit the upload limit, they are being auto-resized somehow? That resulting image is _tiny_:

50 x 29, 32kb

Perhaps this is a regression @sam? 🤔

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [9 april 2020 om 06:27 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/6 "2020-04-09T06:27:31Z")

</div>

Possibly a regression, does this happen with non animated gifs as well?

---

<div class="post-metadata">

### Author: ![Jack\_Vaughan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jack_vaughan/32/209286_2.png) [@Jack\_Vaughan](https://meta.discourse.org/u/Jack_Vaughan)
#### Post date: [9 april 2020 om 09:55 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/7 "2020-04-09T09:55:49Z")

</div>

Thanks guys - I’m using [http://giffox.com/](http://giffox.com/) to make gifs.

Sometimes it works and sometimes not… I think you might be right about the size. Was just doing some tests

Can make it work if it’s very short.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [9 april 2020 om 19:39 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/8 "2020-04-09T19:39:03Z")

</div>

Here is a 2.06 mb GIF

 ![giphy](https://global.discourse-cdn.com/meta/original/3X/5/b/5bc88a56f317efbaaee5758cd083d56cfafd6b8b.gif)

Here is a 3.47 mb GIF

 ![89952-master-strokes-beard-gif-Kill-bdei](https://global.discourse-cdn.com/meta/original/3X/4/8/48094a97eea56661a601c61ef822360a84f35154.gif)

Here is a 9.06 mb GIF

![Ton-Sur-Ton-directed-by-REGAN-CAMERON-1080p](https://global.discourse-cdn.com/meta/original/3X/8/1/811706fb3b224d05e120f40240938b3b257ec266.gif)

Yeah looks like something _very bad_ is happening at the 4mb limit to these @sam @eviltrout. I edited the title to reflect the issue. We got to fix this, we’ve regressed.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [9 april 2020 om 21:37 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/9 "2020-04-09T21:37:46Z")

</div>

Just wanted to confirm this is isolated to animated gifs.

I think we use [Gifsicle: Command-Line Animated GIFs](https://www.lcdf.org/gifsicle/) for resizing do my guess is that params changed

@vinothkannans can you have a quick look today

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [10 april 2020 om 12:52 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/11 "2020-04-10T12:52:06Z")

</div>

[https://github.com/discourse/discourse/commit/b57d4586d713102ce939fd8d17f2ce200f290171](https://github.com/discourse/discourse/commit/b57d4586d713102ce939fd8d17f2ce200f290171)

It’s happening since we changed the way of [image downsizing](https://github.com/discourse/discourse/commit/46d12c5ad3e8116bdc8e1662e55a4e63ed32dfb9). The above commit will fix this issue and the larger gifs will scale down properly.

 ![five](https://global.discourse-cdn.com/meta/original/3X/e/1/e13dda99ca718bc17e3d446c67199a3c83615c8f.gif)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [10 april 2020 om 18:05 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/12 "2020-04-10T18:05:49Z")

</div>

Is this the correct fix? I don’t think we should be “downsizing” what are effectively videos? That feels like a rather extreme (and possibly very server CPU intensive) manipulation, that could ruin video (gif) quality.

I’m not sure about this. I think we should outright reject animated GIFs which are too large rather than shoehorning ourselves into the video resizing (or even better, convert to mp4) business, that is a whole other problem to attack..

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [12 april 2020 om 14:46 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/13 "2020-04-12T14:46:31Z")

</div>

> [@codinghorror](#):
>
> we should outright reject animated GIFs which are too large

Yes, it looks like a straight forward fix. I will change the current functionality.

Anyway, it looks like we’re resizing the GIF images for the last 5 years using “gifsicle” and we didn’t receive any performance issue on it. @zogstrip may know more details.

[https://github.com/discourse/discourse/commit/d456460d33859a3f6890062083ace6f64aa17266](https://github.com/discourse/discourse/commit/d456460d33859a3f6890062083ace6f64aa17266)

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [15 april 2020 om 05:58 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/14 "2020-04-15T05:58:51Z")

</div>

I think in this case, rejecting very specific gifs is going to add more code to our repo.

At the moment we just assume all gifs are “animated” per:

> <https://github.com/discourse/discourse/blob/c670a340138072632dcd986d9cfdd033e2ae275c/app/models/optimized_image.rb#L325-L327>

If we are going to change it so _some_ gifs are rejected we are going to have to do format detection for animated gifs and then drive some special rejection code. This is especially complicated for images we have to optimize (due to dimensions) cause we will no longer be able to optimize animated gifs.

On the upside we get to get rid of the [gifsicle](https://www.lcdf.org/gifsicle/) dependency. On the downside our upload pipeline becomes more complex.

Personally I think @vinothkannans fix is fine and low risk, it is code we have had for 5 years and there are no huge perf issues I know about.

That said @codinghorror I would not wrestle here if you want to nuke support for animated gif resizing but it is a fairly complex change, identification is easy enough, but driving the rejection with an error message may be a bit tricky.

> Your animated gif is larger than 10mb so it can not be uploaded

> Your animated gif is larger than 600x400 so it can not be uploaded

Anyway your call here. My call is just to leave the fix as is and move on but if you want to kill support let us know.

Note, this removal will also require we remove support for animated avatars (an optional feature, I am not super happy we have to be honest)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [15 april 2020 om 06:25 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/15 "2020-04-15T06:25:10Z")

</div>

Hmm, so as long as the animated GIF fits in the total upload size bucket (??), it effectively gets its .. “video” quality reduced to match.. what?

I’m super unclear what is actually happening here.

Obviously resizing height and width is totally inappropriate for a GIF.. that’s what led to the original bug above?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [15 april 2020 om 06:42 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/16 "2020-04-15T06:42:16Z")

</div>

The history was that we were “destroying” animated gifs when we were optimizing so if you uploaded images that was to be lightboxed we would butcher it.

Internals of our code had no “detection” logic to figure out if a GIF was animated or not. The lightboxing happens after the post is committed to the database.

The fix was to make our “resize” code not butcher animated gifs and work properly with them.

The problem is that we need to redo chunks of our upload pipeline to give “special handling” for animated gifs if we are stripping support.

- Gif is uploaded
  - Is it an animated gif?
    - Is the pre-processor going to need to resize it?
      - reject animated gif

    - is the post processor going to need to optimize it?
      - reject animated gif

  - Is it not an animated gif?
    - let it through with normal pipeline

There are also some side effects to consider with long term rebaking of markdown if params ever change and pulling hotlinked images.

The fix of simply fixing resizing meant that we did not need to worry about this stuff.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [15 april 2020 om 23:33 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/17 "2020-04-15T23:33:29Z")

</div>

> [@sam](#):
>
> we will no longer be able to optimize animated gifs

I don’t feel we should be doing “optimization” on animated gifs at all, so I think the code needs to detect this. Adding that path would open the door for eventual gif to mp4 video conversion which we want anyway.. eventually. So I feel this is necessary work.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [16 april 2020 om 00:07 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/18 "2020-04-16T00:07:06Z")

</div>

Just to clarify.

You would like us

1. To nuke `gifsicle` out of our docker image
2. When you rebake old posts that had resized animated gifs, they should show up broken image glyph in the post
3. Fix our pull hotlinked images task, to bypass pulling gifs that are animated that required a resize, displaying a link instead
4. Reject animated gifs that are either too big (dimension or size) and are animated
5. Remove support for animated avatars from Discourse.
6. Keep track of animated vs not animated in the uploads table.

We are looking at about 1-2 weeks of fiddly work here, just confirming you want us to take it, especially since stuff is working right now.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [16 april 2020 om 02:25 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/19 "2020-04-16T02:25:27Z")

</div>

> [@sam](#):
>
> To nuke `gifsicle` out of our docker image

Sure, less dependencies is better, isn’t it?

> [@sam](#):
>
> When you rebake old posts that had resized animated gifs, they should show up broken image glyph in the post

Probably OK

> [@sam](#):
>
> Fix our pull hotlinked images task, to bypass pulling gifs that are animated that required a resize, displaying a link instead

Simply check remote file size. If it’s too big, don’t pull. I do not care otherwise.

> [@sam](#):
>
> Reject animated gifs that are either too big (dimension or size) and are animated

Yes, mostly file size will be an issue I’d expect, long before height and width dimensions really matter. (In sing-song Twilight Zone “another dimension.. _the dimension of tiiiiime_”) This is also why it’s so frickin’ weird to treat an image like a video. They are rather different animals!

> [@sam](#):
>
> Remove support for animated avatars from Discourse.

Yes, nobody sane wants this.

> [@sam](#):
>
> Keep track of animated vs not animated in the uploads table.

**We need this code path** because we should _eventually_ auto-convert GIFs to MP4s anyway. This gets us part of the way there and that’s a net positive to the world.

---

<div class="post-metadata">

### Author: ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)
#### Post date: [3 augustus 2020 om 08:54 UTC](https://meta.discourse.org/t/uploaded-animated-gifs-of-4mb-or-larger-appear-very-small/147107/25 "2020-08-03T08:54:53Z")

</div>

I removed the dependency of `gifsicle` in:

[https://github.com/discourse/discourse/pull/10357](https://github.com/discourse/discourse/pull/10357)
