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
8b16370b
Commit
8b16370b
authored
Mar 29, 2016
by
Jacob Bullock
Committed by
Tute Costa
Aug 23, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow user to specify frame_index for videos or PDFs
[closes #2155]
parent
fa58ec38
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
4 deletions
+49
-4
lib/paperclip/thumbnail.rb
+14
-4
spec/paperclip/thumbnail_spec.rb
+35
-0
No files found.
lib/paperclip/thumbnail.rb
View file @
8b16370b
...
...
@@ -3,10 +3,11 @@ module Paperclip
class
Thumbnail
<
Processor
attr_accessor
:current_geometry
,
:target_geometry
,
:format
,
:whiny
,
:convert_options
,
:source_file_options
,
:animated
,
:auto_orient
:source_file_options
,
:animated
,
:auto_orient
,
:frame_index
# List of formats that we need to preserve animation
ANIMATED_FORMATS
=
%w(gif)
MULTI_FRAME_FORMATS
=
%w(.mkv .avi .mp4 .mov .mpg .mpeg .gif)
# Creates a Thumbnail object set to work on the +file+ given. It
# will attempt to transform the image into one defined by +target_geometry+
...
...
@@ -25,6 +26,7 @@ module Paperclip
# +whiny+ - whether to raise an error when processing fails. Defaults to true
# +format+ - the desired filename extension
# +animated+ - whether to merge all the layers in the image. Defaults to true
# +frame_index+ - the frame index of the source file to render as the thumbnail
def
initialize
(
file
,
options
=
{},
attachment
=
nil
)
super
...
...
@@ -41,12 +43,12 @@ module Paperclip
if
@auto_orient
&&
@current_geometry
.
respond_to?
(
:auto_orient
)
@current_geometry
.
auto_orient
end
@source_file_options
=
@source_file_options
.
split
(
/\s+/
)
if
@source_file_options
.
respond_to?
(
:split
)
@convert_options
=
@convert_options
.
split
(
/\s+/
)
if
@convert_options
.
respond_to?
(
:split
)
@current_format
=
File
.
extname
(
@file
.
path
)
@basename
=
File
.
basename
(
@file
.
path
,
@current_format
)
@frame_index
=
multi_frame_format?
?
options
.
fetch
(:
frame_index
,
0
)
:
0
end
# Returns true if the +target_geometry+ is meant to crop.
...
...
@@ -76,7 +78,12 @@ module Paperclip
parameters
=
parameters
.
flatten
.
compact
.
join
(
" "
).
strip
.
squeeze
(
" "
)
success
=
convert
(
parameters
,
:source
=>
"
#{
File
.
expand_path
(
src
.
path
)
}#{
'[0]'
unless
animated?
}
"
,
:dest
=>
File
.
expand_path
(
dst
.
path
))
frame
=
animated?
?
""
:
"[
#{
@frame_index
}
]"
convert
(
parameters
,
source:
"
#{
File
.
expand_path
(
src
.
path
)
}#{
frame
}
"
,
dest:
File
.
expand_path
(
dst
.
path
),
)
rescue
Cocaine
::
ExitStatusError
=>
e
raise
Paperclip
::
Error
,
"There was an error processing the thumbnail for
#{
@basename
}
"
if
@whiny
rescue
Cocaine
::
CommandNotFoundError
=>
e
...
...
@@ -101,7 +108,10 @@ module Paperclip
protected
# Return true if the format is animated
def
multi_frame_format?
MULTI_FRAME_FORMATS
.
include?
@current_format
end
def
animated?
@animated
&&
(
ANIMATED_FORMATS
.
include?
(
@format
.
to_s
)
||
@format
.
blank?
)
&&
identified_as_animated?
end
...
...
spec/paperclip/thumbnail_spec.rb
View file @
8b16370b
...
...
@@ -480,6 +480,41 @@ describe Paperclip::Thumbnail do
assert_equal
"50x50"
,
`
#{
cmd
}
`
.
chomp
end
end
context
"with a specified frame_index"
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
"50x50"
,
frame_index:
5
,
format: :jpg
,
)
end
it
"creates the thumbnail from the frame index when sent #make"
do
@thumb
.
make
assert_equal
5
,
@thumb
.
frame_index
end
end
context
"with a specified frame_index out of bounds"
do
before
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
geometry:
"50x50"
,
frame_index:
20
,
format: :jpg
,
)
end
it
"errors when trying to create the thumbnail"
do
assert_raises
(
Paperclip
::
Error
)
do
silence_stream
(
STDERR
)
do
@thumb
.
make
end
end
end
end
end
context
"with a really long file name"
do
...
...
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