Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Animated GIF support? #851

Closed
rickypai opened this Issue · 9 comments

3 participants

@rickypai

I know this question has already been asked too many times. I digged through the wiki with no luck. But the source code there is an option :animated in /lib/paperclip/style.rb

so I implemented the attachment with the animated options:

has_attached_file :banner, :styles => { :cover_200x40 => {:geometry =>'200x40#',:animated => true}}

but the files i uploaded are still not animated. changed the file format to GIF:

has_attached_file :banner, :styles => { :cover_200x40 => {:geometry =>'200x40#',:animated => true, :format => 'GIF'}}

and still not animated.

Is this option actually valid?

the line I am using to output the image file is:

<img src="<%=event.banner.url(:cover_200x40)%>"/>

thanks in advance.

@sikachu
Owner

Yep, and by default Paperclip will animate the gif file. What happen if you run identify on that file? Do you get multiple frames like this?

[master][~/Projects/paperclip/test/fixtures] identify animated.gif 
animated.gif[0] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
animated.gif[1] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
animated.gif[2] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
animated.gif[3] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
animated.gif[4] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
animated.gif[5] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
animated.gif[6] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
animated.gif[7] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
animated.gif[8] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
animated.gif[9] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
animated.gif[10] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
animated.gif[11] GIF 100x100 100x100+0+0 8-bit PseudoClass 32c 8.24KB 0.000u 0:00.009
@rickypai

/public/uploads/events/banners/1/cover_200x40$ identify 23310681cbdff365b7799d8fc3a474b794ecba81-1335985233.gif
23310681cbdff365b7799d8fc3a474b794ecba81-1335985233.gif GIF 200x40 200x40+0+0 8-bit PseudoClass 256c 5.36KB 0.000u 0:00.000

/public/uploads/events/banners/1/original$ identify a7009f1a2e21d165d9ee44dd1cfc78f41f7d61cf-1335985233.gif

a7009f1a2e21d165d9ee44dd1cfc78f41f7d61cf-1335985233.gif[0] GIF 200x40 200x40+0+0 8-bit PseudoClass 256c 14.4KB 0.000u 0:00.000
a7009f1a2e21d165d9ee44dd1cfc78f41f7d61cf-1335985233.gif[1] GIF 22x18 200x40+134+17 8-bit PseudoClass 256c 14.4KB 0.000u 0:00.000
a7009f1a2e21d165d9ee44dd1cfc78f41f7d61cf-1335985233.gif[2] GIF 24x17 200x40+153+17 8-bit PseudoClass 256c 14.4KB 0.000u 0:00.000
a7009f1a2e21d165d9ee44dd1cfc78f41f7d61cf-1335985233.gif[3] GIF 112x38 200x40+83+0 8-bit PseudoClass 256c 14.4KB 0.000u 0:00.000
a7009f1a2e21d165d9ee44dd1cfc78f41f7d61cf-1335985233.gif[4] GIF 114x23 200x40+81+14 8-bit PseudoClass 256c 14.4KB 0.000u 0:00.000
a7009f1a2e21d165d9ee44dd1cfc78f41f7d61cf-1335985233.gif[5] GIF 115x24 200x40+81+14 8-bit PseudoClass 256c 14.4KB 0.000u 0:00.000
a7009f1a2e21d165d9ee44dd1cfc78f41f7d61cf-1335985233.gif[6] GIF 113x24 200x40+83+14 8-bit PseudoClass 256c 14.4KB 0.000u 0:00.000
a7009f1a2e21d165d9ee44dd1cfc78f41f7d61cf-1335985233.gif[7] GIF 113x38 200x40+82+0 8-bit PseudoClass 256c 14.4KB 0.000u 0:00.000

@sikachu
Owner

Interesting. Let me check to see if this is really broken or not. We have a test case for that, but not sure if I overlooked something

By the way, there is a log when imagemagick process the file (in your environment log file.) Do you mind grabbing that and post it in here as well? It should be those lines that has convert command. Thank you.

@rickypai

CACHE (0.0ms) SELECT events.* FROM events WHERE events.id = LIMIT 1
(0.1ms) BEGIN
Command :: identify -format %wx%h '/tmp/poptart1red1.gif20120502-11751-1eqbf84[0]'
Command :: convert '/tmp/poptart1red1.gif20120502-11751-1eqbf84[0]' -resize "200x" -crop "200x40+0+80" +repage '/tmp/poptart1red120120502-11751-1dhia8c.gif'
(0.6ms) UPDATE events SET banner_file_name = 'poptart1red1.gif', banner_content_type = 'image/gif', banner_file_size = 30329, banner_updated_at = '2012-05-02 19:02:16', updated_at = '2012-05-02 19:02:17' WHERE events.id = 2

Thanks a lot!

@sikachu
Owner

Hmm ... seems like the tmp file name is /tmp/poptart1red1.gif20120502-11751-1eqbf84, which makes Paperclip fails to detect its file type. Let me try to reproduce this problem in the test case, as we might have to patch the Tempfile object again.

Also, what operating system are you on, and what version of Ruby/Rails?

@rickypai

Ubuntu 11.10 (GNU/Linux 3.0.0-12-generic i686) with Rails 3.1.1

Please let me know what else you need!

@sikachu
Owner

Hmm ... seems like this problem also happen on Mac OS. Going to fix this now.

@sikachu sikachu closed this issue from a commit
@sikachu sikachu Force Tempfile extension when creating a Tempfile
This should fix the problem on animated file detection.

Fixes #851
48736ce
@sikachu sikachu closed this in 48736ce
@sikachu
Owner

I've fixed this. Thanks again for reporting in.

@fun-ruby

@sikachu, I may be too late to chime in. I want to have this feature - to convert animated gif to normal gif. Is there a way to tell paperclip to do so?

Thanks,
Long

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.