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
2826cdb7
Commit
2826cdb7
authored
Jul 09, 2009
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added options to the source file when processing thumbnails
parent
121609fa
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletions
+41
-1
lib/paperclip/thumbnail.rb
+3
-1
test/thumbnail_test.rb
+38
-0
No files found.
lib/paperclip/thumbnail.rb
View file @
2826cdb7
...
...
@@ -2,7 +2,7 @@ module Paperclip
# Handles thumbnailing images that are uploaded.
class
Thumbnail
<
Processor
attr_accessor
:current_geometry
,
:target_geometry
,
:format
,
:whiny
,
:convert_options
attr_accessor
:current_geometry
,
:target_geometry
,
:format
,
:whiny
,
:convert_options
,
:source_file_options
# Creates a Thumbnail object set to work on the +file+ given. It
# will attempt to transform the image into one defined by +target_geometry+
...
...
@@ -17,6 +17,7 @@ module Paperclip
@crop
=
geometry
[
-
1
,
1
]
==
'#'
@target_geometry
=
Geometry
.
parse
geometry
@current_geometry
=
Geometry
.
from_file
@file
@source_file_options
=
options
[
:source_file_options
]
@convert_options
=
options
[
:convert_options
]
@whiny
=
options
[
:whiny
].
nil?
?
true
:
options
[
:whiny
]
@format
=
options
[
:format
]
...
...
@@ -43,6 +44,7 @@ module Paperclip
dst
.
binmode
command
=
<<-
end_command
#{
source_file_options
}
"
#{
File
.
expand_path
(
src
.
path
)
}
[0]"
#{
transformation_command
}
"
#{
File
.
expand_path
(
dst
.
path
)
}
"
...
...
test/thumbnail_test.rb
View file @
2826cdb7
...
...
@@ -103,6 +103,44 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
context
"being thumbnailed with source file options set"
do
setup
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
,
:source_file_options
=>
"-strip"
)
end
should
"have source_file_options value set"
do
assert_equal
"-strip"
,
@thumb
.
source_file_options
end
should
"send the right command to convert when sent #make"
do
Paperclip
.
expects
(
:"`"
).
with
do
|
arg
|
arg
.
match
%r{convert
\s
+-strip
\s
+"
#{
File
.
expand_path
(
@thumb
.
file
.
path
)
}
\[
0
\]
"
\s
+-resize
\s
+"x50"
\s
+-crop
\s
+"100x50
\+
114
\+
0"
\s
+
\+
repage
\s
+".*?"}
end
@thumb
.
make
end
should
"create the thumbnail when sent #make"
do
dst
=
@thumb
.
make
assert_match
/100x50/
,
`identify "
#{
dst
.
path
}
"`
end
context
"redefined to have bad source_file_options setting"
do
setup
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
,
:source_file_options
=>
"-this-aint-no-option"
)
end
should
"error when trying to create the thumbnail"
do
assert_raises
(
Paperclip
::
PaperclipError
)
do
@thumb
.
make
end
end
end
end
context
"being thumbnailed with convert options set"
do
setup
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
...
...
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