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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
11 deletions
+51
-11
lib/paperclip/thumbnail.rb
+13
-11
test/thumbnail_test.rb
+38
-0
No files found.
lib/paperclip/thumbnail.rb
View file @
2826cdb7
...
@@ -2,7 +2,7 @@ module Paperclip
...
@@ -2,7 +2,7 @@ module Paperclip
# Handles thumbnailing images that are uploaded.
# Handles thumbnailing images that are uploaded.
class
Thumbnail
<
Processor
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
# Creates a Thumbnail object set to work on the +file+ given. It
# will attempt to transform the image into one defined by +target_geometry+
# will attempt to transform the image into one defined by +target_geometry+
...
@@ -12,17 +12,18 @@ module Paperclip
...
@@ -12,17 +12,18 @@ module Paperclip
# set, the options will be appended to the convert command upon image conversion
# set, the options will be appended to the convert command upon image conversion
def
initialize
file
,
options
=
{},
attachment
=
nil
def
initialize
file
,
options
=
{},
attachment
=
nil
super
super
geometry
=
options
[
:geometry
]
geometry
=
options
[
:geometry
]
@file
=
file
@file
=
file
@crop
=
geometry
[
-
1
,
1
]
==
'#'
@crop
=
geometry
[
-
1
,
1
]
==
'#'
@target_geometry
=
Geometry
.
parse
geometry
@target_geometry
=
Geometry
.
parse
geometry
@current_geometry
=
Geometry
.
from_file
@file
@current_geometry
=
Geometry
.
from_file
@file
@convert_options
=
options
[
:convert_options
]
@source_file_options
=
options
[
:source_file_options
]
@whiny
=
options
[
:whiny
].
nil?
?
true
:
options
[
:whiny
]
@convert_options
=
options
[
:convert_options
]
@format
=
options
[
:format
]
@whiny
=
options
[
:whiny
].
nil?
?
true
:
options
[
:whiny
]
@format
=
options
[
:format
]
@current_format
=
File
.
extname
(
@file
.
path
)
@current_format
=
File
.
extname
(
@file
.
path
)
@basename
=
File
.
basename
(
@file
.
path
,
@current_format
)
@basename
=
File
.
basename
(
@file
.
path
,
@current_format
)
end
end
# Returns true if the +target_geometry+ is meant to crop.
# Returns true if the +target_geometry+ is meant to crop.
...
@@ -43,6 +44,7 @@ module Paperclip
...
@@ -43,6 +44,7 @@ module Paperclip
dst
.
binmode
dst
.
binmode
command
=
<<-
end_command
command
=
<<-
end_command
#{
source_file_options
}
"
#{
File
.
expand_path
(
src
.
path
)
}
[0]"
"
#{
File
.
expand_path
(
src
.
path
)
}
[0]"
#{
transformation_command
}
#{
transformation_command
}
"
#{
File
.
expand_path
(
dst
.
path
)
}
"
"
#{
File
.
expand_path
(
dst
.
path
)
}
"
...
...
test/thumbnail_test.rb
View file @
2826cdb7
...
@@ -103,6 +103,44 @@ class ThumbnailTest < Test::Unit::TestCase
...
@@ -103,6 +103,44 @@ class ThumbnailTest < Test::Unit::TestCase
end
end
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
context
"being thumbnailed with convert options set"
do
setup
do
setup
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
@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