Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
c54708f2
Commit
c54708f2
authored
May 18, 2012
by
Juanjo Bazán
Committed by
Mike Burns
Jun 06, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Identify animated formats using ImageMagick.
parent
cdfc4cfa
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
1 deletions
+55
-1
lib/paperclip/thumbnail.rb
+10
-1
test/fixtures/animated
+0
-0
test/fixtures/animated.unknown
+0
-0
test/thumbnail_test.rb
+45
-0
No files found.
lib/paperclip/thumbnail.rb
View file @
c54708f2
...
@@ -98,7 +98,16 @@ module Paperclip
...
@@ -98,7 +98,16 @@ module Paperclip
# Return true if the format is animated
# Return true if the format is animated
def
animated?
def
animated?
@animated
&&
ANIMATED_FORMATS
.
include?
(
@current_format
[
1
..-
1
])
&&
(
ANIMATED_FORMATS
.
include?
(
@format
.
to_s
)
||
@format
.
blank?
)
@animated
&&
(
ANIMATED_FORMATS
.
include?
(
@format
.
to_s
)
||
@format
.
blank?
)
&&
identified_as_animated?
end
# Return true if ImageMagick's +identify+ returns an animated format
def
identified_as_animated?
ANIMATED_FORMATS
.
include?
identify
(
"-format %m :file"
,
:file
=>
"
#{
@file
.
path
}
[0]"
).
to_s
.
downcase
.
strip
rescue
Cocaine
::
ExitStatusError
=>
e
raise
Paperclip
::
Error
,
"There was an error running `identify` for
#{
@basename
}
"
if
@whiny
rescue
Cocaine
::
CommandNotFoundError
=>
e
raise
Paperclip
::
Errors
::
CommandNotFoundError
.
new
(
"Could not run the `identify` command. Please install ImageMagick."
)
end
end
end
end
end
end
test/fixtures/animated
0 → 100644
View file @
c54708f2
File added
test/fixtures/animated.unknown
0 → 100644
View file @
c54708f2
File added
test/thumbnail_test.rb
View file @
c54708f2
...
@@ -234,6 +234,17 @@ class ThumbnailTest < Test::Unit::TestCase
...
@@ -234,6 +234,17 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
end
end
context
"being thumbnailed with default animated option (true)"
do
should
"call identify to check for animated images when sent #make"
do
thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
)
thumb
.
expects
(
:identify
).
at_least_once
.
with
do
|*
arg
|
arg
[
0
]
==
'-format %m :file'
&&
arg
[
1
][
:file
]
==
"
#{
File
.
expand_path
(
thumb
.
file
.
path
)
}
[0]"
end
thumb
.
make
end
end
context
"passing a custom file geometry parser"
do
context
"passing a custom file geometry parser"
do
teardown
do
teardown
do
self
.
class
.
send
(
:remove_const
,
:GeoParser
)
self
.
class
.
send
(
:remove_const
,
:GeoParser
)
...
@@ -380,6 +391,40 @@ class ThumbnailTest < Test::Unit::TestCase
...
@@ -380,6 +391,40 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
end
end
context
"with unidentified source format"
do
setup
do
@unidentified_file
=
File
.
new
(
fixture_file
(
"animated.unknown"
),
'rb'
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"60x60"
)
end
should
"create the 12 frames thumbnail when sent #make"
do
dst
=
@thumb
.
make
cmd
=
%Q[identify -format "%wx%h" "
#{
dst
.
path
}
"]
assert_equal
"60x60"
*
12
,
`
#{
cmd
}
`
.
chomp
end
should
"use the -coalesce option"
do
assert_equal
@thumb
.
transformation_command
.
first
,
"-coalesce"
end
end
context
"with no source format"
do
setup
do
@unidentified_file
=
File
.
new
(
fixture_file
(
"animated"
),
'rb'
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"70x70"
)
end
should
"create the 12 frames thumbnail when sent #make"
do
dst
=
@thumb
.
make
cmd
=
%Q[identify -format "%wx%h" "
#{
dst
.
path
}
"]
assert_equal
"70x70"
*
12
,
`
#{
cmd
}
`
.
chomp
end
should
"use the -coalesce option"
do
assert_equal
@thumb
.
transformation_command
.
first
,
"-coalesce"
end
end
context
"with animated option set to false"
do
context
"with animated option set to false"
do
setup
do
setup
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"50x50"
,
:animated
=>
false
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"50x50"
,
:animated
=>
false
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment