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
c0257f81
Commit
c0257f81
authored
Aug 07, 2008
by
Barry Hess
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add convert_options to attachment definition and thumbnail's transformation command line.
parent
0c0867d4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
6 deletions
+16
-6
lib/paperclip/attachment.rb
+3
-1
lib/paperclip/thumbnail.rb
+13
-5
No files found.
lib/paperclip/attachment.rb
View file @
c0257f81
...
@@ -34,6 +34,7 @@ module Paperclip
...
@@ -34,6 +34,7 @@ module Paperclip
@default_style
=
options
[
:default_style
]
@default_style
=
options
[
:default_style
]
@storage
=
options
[
:storage
]
@storage
=
options
[
:storage
]
@whiny_thumbnails
=
options
[
:whiny_thumbnails
]
@whiny_thumbnails
=
options
[
:whiny_thumbnails
]
@convert_options
=
options
[
:thumbnail_convert_options
]
@options
=
options
@options
=
options
@queued_for_delete
=
[]
@queued_for_delete
=
[]
@queued_for_write
=
{}
@queued_for_write
=
{}
...
@@ -241,7 +242,8 @@ module Paperclip
...
@@ -241,7 +242,8 @@ module Paperclip
@queued_for_write
[
name
]
=
Thumbnail
.
make
(
@queued_for_write
[
:original
],
@queued_for_write
[
name
]
=
Thumbnail
.
make
(
@queued_for_write
[
:original
],
dimensions
,
dimensions
,
format
,
format
,
@whiny_thumnails
)
@whiny_thumnails
,
@convert_options
)
rescue
PaperclipError
=>
e
rescue
PaperclipError
=>
e
@errors
<<
e
.
message
if
@whiny_thumbnails
@errors
<<
e
.
message
if
@whiny_thumbnails
end
end
...
...
lib/paperclip/thumbnail.rb
View file @
c0257f81
...
@@ -2,19 +2,21 @@ module Paperclip
...
@@ -2,19 +2,21 @@ module Paperclip
# Handles thumbnailing images that are uploaded.
# Handles thumbnailing images that are uploaded.
class
Thumbnail
class
Thumbnail
attr_accessor
:file
,
:current_geometry
,
:target_geometry
,
:format
,
:whiny_thumbnails
attr_accessor
:file
,
:current_geometry
,
:target_geometry
,
:format
,
:whiny_thumbnails
,
:convert_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+
# which is a "WxH"-style string. +format+ will be inferred from the +file+
# which is a "WxH"-style string. +format+ will be inferred from the +file+
# unless specified. Thumbnail creation will raise no errors unless
# unless specified. Thumbnail creation will raise no errors unless
# +whiny_thumbnails+ is true (which it is, by default.
# +whiny_thumbnails+ is true (which it is, by default. If +convert_options+ is
def
initialize
file
,
target_geometry
,
format
=
nil
,
whiny_thumbnails
=
true
# set, the options will be appended to the convert command upon image conversion
def
initialize
file
,
target_geometry
,
format
=
nil
,
whiny_thumbnails
=
true
,
convert_options
=
nil
@file
=
file
@file
=
file
@crop
=
target_geometry
[
-
1
,
1
]
==
'#'
@crop
=
target_geometry
[
-
1
,
1
]
==
'#'
@target_geometry
=
Geometry
.
parse
target_geometry
@target_geometry
=
Geometry
.
parse
target_geometry
@current_geometry
=
Geometry
.
from_file
file
@current_geometry
=
Geometry
.
from_file
file
@whiny_thumbnails
=
whiny_thumbnails
@whiny_thumbnails
=
whiny_thumbnails
@convert_options
=
convert_options
@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
)
...
@@ -24,14 +26,19 @@ module Paperclip
...
@@ -24,14 +26,19 @@ module Paperclip
# Creates a thumbnail, as specified in +initialize+, +make+s it, and returns the
# Creates a thumbnail, as specified in +initialize+, +make+s it, and returns the
# resulting Tempfile.
# resulting Tempfile.
def
self
.
make
file
,
dimensions
,
format
=
nil
,
whiny_thumbnails
=
true
def
self
.
make
file
,
dimensions
,
format
=
nil
,
whiny_thumbnails
=
true
,
convert_options
=
nil
new
(
file
,
dimensions
,
format
,
whiny_thumbnails
).
make
new
(
file
,
dimensions
,
format
,
whiny_thumbnails
,
convert_options
).
make
end
end
# Returns true if the +target_geometry+ is meant to crop.
# Returns true if the +target_geometry+ is meant to crop.
def
crop?
def
crop?
@crop
@crop
end
end
# Returns true if the image is meant to make use of additional convert options.
def
convert_options?
@convert_options
end
# Performs the conversion of the +file+ into a thumbnail. Returns the Tempfile
# Performs the conversion of the +file+ into a thumbnail. Returns the Tempfile
# that contains the new image.
# that contains the new image.
...
@@ -61,6 +68,7 @@ module Paperclip
...
@@ -61,6 +68,7 @@ module Paperclip
scale
,
crop
=
@current_geometry
.
transformation_to
(
@target_geometry
,
crop?
)
scale
,
crop
=
@current_geometry
.
transformation_to
(
@target_geometry
,
crop?
)
trans
=
"-scale
\"
#{
scale
}
\"
"
trans
=
"-scale
\"
#{
scale
}
\"
"
trans
<<
" -crop
\"
#{
crop
}
\"
+repage"
if
crop
trans
<<
" -crop
\"
#{
crop
}
\"
+repage"
if
crop
trans
<<
"
#{
convert_options
}
"
if
convert_options?
trans
trans
end
end
end
end
...
...
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