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
ee70992b
Commit
ee70992b
authored
Dec 23, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Thumbnail takes a hash of options instead of a list of args now
parent
9dc9f71f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
19 deletions
+23
-19
lib/paperclip/thumbnail.rb
+13
-13
test/thumbnail_test.rb
+10
-6
No files found.
lib/paperclip/thumbnail.rb
View file @
ee70992b
...
...
@@ -2,32 +2,32 @@ module Paperclip
# Handles thumbnailing images that are uploaded.
class
Thumbnail
attr_accessor
:file
,
:current_geometry
,
:target_geometry
,
:format
,
:whiny
_thumbnails
,
:convert_options
attr_accessor
:file
,
:current_geometry
,
:target_geometry
,
:format
,
:whiny
,
:convert_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+
# which is a "WxH"-style string. +format+ will be inferred from the +file+
# unless specified. Thumbnail creation will raise no errors unless
# +whiny
_thumbnails
+ is true (which it is, by default. If +convert_options+ is
# +whiny+ is true (which it is, by default. If +convert_options+ is
# set, the options will be appended to the convert command upon image conversion
def
initialize
file
,
target_geometry
,
format
=
nil
,
convert_options
=
nil
,
whiny_thumbnails
=
true
def
initialize
file
,
options
=
{}
geometry
=
options
[
:geometry
]
@file
=
file
@crop
=
target_geometry
[
-
1
,
1
]
==
'#'
@target_geometry
=
Geometry
.
parse
target_geometry
@current_geometry
=
Geometry
.
from_file
file
@convert_options
=
convert_options
@whiny_thumbnails
=
whiny_thumbnails
@crop
=
geometry
[
-
1
,
1
]
==
'#'
@target_geometry
=
Geometry
.
parse
geometry
@current_geometry
=
Geometry
.
from_file
@file
@convert_options
=
options
[
:convert_options
]
@whiny
=
options
[
:whiny
].
nil?
?
true
:
options
[
:whiny
]
@format
=
options
[
:format
]
@current_format
=
File
.
extname
(
@file
.
path
)
@basename
=
File
.
basename
(
@file
.
path
,
@current_format
)
@format
=
format
end
# Creates a thumbnail, as specified in +initialize+, +make+s it, and returns the
# resulting Tempfile.
def
self
.
make
file
,
dimensions
,
format
=
nil
,
convert_options
=
nil
,
whiny_thumbnails
=
true
new
(
file
,
dimensions
,
format
,
convert_options
,
whiny_thumbnail
s
).
make
def
self
.
make
file
,
options
=
{}
new
(
file
,
option
s
).
make
end
# Returns true if the +target_geometry+ is meant to crop.
...
...
@@ -56,7 +56,7 @@ module Paperclip
begin
success
=
Paperclip
.
run
(
"convert"
,
command
.
gsub
(
/\s+/
,
" "
))
rescue
PaperclipCommandLineError
raise
PaperclipError
,
"There was an error processing the thumbnail for
#{
@basename
}
"
if
@whiny
_thumbnails
raise
PaperclipError
,
"There was an error processing the thumbnail for
#{
@basename
}
"
if
@whiny
end
dst
...
...
test/thumbnail_test.rb
View file @
ee70992b
...
...
@@ -41,7 +41,7 @@ class ThumbnailTest < Test::Unit::TestCase
].
each
do
|
args
|
context
"being thumbnailed with a geometry of
#{
args
[
0
]
}
"
do
setup
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
args
[
0
])
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
args
[
0
])
end
should
"start with dimensions of 434x66"
do
...
...
@@ -68,7 +68,7 @@ class ThumbnailTest < Test::Unit::TestCase
context
"being thumbnailed at 100x50 with cropping"
do
setup
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
"100x50#"
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
)
end
should
"report its correct current and target geometries"
do
...
...
@@ -80,8 +80,8 @@ class ThumbnailTest < Test::Unit::TestCase
assert_nil
@thumb
.
format
end
should
"have whiny
_thumbnails
turned on by default"
do
assert
@thumb
.
whiny
_thumbnails
should
"have whiny turned on by default"
do
assert
@thumb
.
whiny
end
should
"have convert_options set to nil by default"
do
...
...
@@ -103,7 +103,9 @@ class ThumbnailTest < Test::Unit::TestCase
context
"being thumbnailed with convert options set"
do
setup
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
"100x50#"
,
format
=
nil
,
convert_options
=
"-strip -depth 8"
,
whiny_thumbnails
=
true
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
,
:convert_options
=>
"-strip -depth 8"
)
end
should
"have convert_options value set"
do
...
...
@@ -124,7 +126,9 @@ class ThumbnailTest < Test::Unit::TestCase
context
"redefined to have bad convert_options setting"
do
setup
do
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
"100x50#"
,
format
=
nil
,
convert_options
=
"-this-aint-no-option"
,
whiny_thumbnails
=
true
)
@thumb
=
Paperclip
::
Thumbnail
.
new
(
@file
,
:geometry
=>
"100x50#"
,
:convert_options
=>
"-this-aint-no-option"
)
end
should
"error when trying to create the thumbnail"
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